c#连接数据库的,在一张表中求一行数据多列数据的和,并且将值赋值个一个textbox中,求代码或者一个例子
数据查询语句"selectsum(Bcopper+Baluminum+BCandA+CMyield+CJCandA)fromCCA_Sys_wastedatawhere"...
数据查询语句
"select sum( Bcopper + Baluminum + BCandA + CMyield + CJCandA) from CCA_Sys_wastedata where " +
"WorkGroupName='甲班'and (Date between '" + strendshijian1 + "'and'" + strendshijian2 + "')";
讨论Q号 1028559382 展开
"select sum( Bcopper + Baluminum + BCandA + CMyield + CJCandA) from CCA_Sys_wastedata where " +
"WorkGroupName='甲班'and (Date between '" + strendshijian1 + "'and'" + strendshijian2 + "')";
讨论Q号 1028559382 展开
1个回答
展开全部
好吧!我接着回答你的问题,数据库连接和查询方法你会不?
SqlConnection sqlCon = new SqlConnection();
sqlCon.ConnectionString = "Data Source=数据库实例名;Initial Catalog=数据库名;User Id=sa;Password=123456;";
sqlCon.Open();
打开连接后 查询语句:
public DataSet GetDataSet(string sql)
{
string sql = "select sum( Bcopper + Baluminum + BCandA + CMyield + CJCandA) from CCA_Sys_wastedata where " + "WorkGroupName='甲班'and (Date between '" + strendshijian1 + "'and'" + strendshijian2 + "')";
SqlDataAdapter ada = new SqlDataAdapter(sql,conn );
DataSet ds = new DataSet();
ada.Fill(ds);
textbox.text = ds.Table[0].Rows[0][0].ToString();
}
我只能帮你到这了
SqlConnection sqlCon = new SqlConnection();
sqlCon.ConnectionString = "Data Source=数据库实例名;Initial Catalog=数据库名;User Id=sa;Password=123456;";
sqlCon.Open();
打开连接后 查询语句:
public DataSet GetDataSet(string sql)
{
string sql = "select sum( Bcopper + Baluminum + BCandA + CMyield + CJCandA) from CCA_Sys_wastedata where " + "WorkGroupName='甲班'and (Date between '" + strendshijian1 + "'and'" + strendshijian2 + "')";
SqlDataAdapter ada = new SqlDataAdapter(sql,conn );
DataSet ds = new DataSet();
ada.Fill(ds);
textbox.text = ds.Table[0].Rows[0][0].ToString();
}
我只能帮你到这了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询