SqlCommand comm1 = new SqlCommand(sql1, conn);
int i = (int)comm1.ExecuteScalar();--如果是浮点型用float
然后赋值给textBox1.Text=i.ToString();
第一种解决方案:textBox1.Text = SDR[0].ToString();
第二种解决方案:
conn.Open();
string sql1 = "SELECT SUM(AAA) as AAAsum FROM O WHERE CCC = '" +123.Text.Trim()+"'";
SqlCommand comm1 = new SqlCommand(sql1, conn);
SqlDataReader SDR = comm1.ExecuteReader();
while (SDR.Read())
{
textBox1.Text = SDR["AAAsum"].ToString();//这里不会写
}
SDR.Close();
还可以SDR.Get什么的忘了,不过VS可以点出来,是一个方法,要的是下标,你给就行,建议你用第二种
textBox1.Text = SDR["SUM(AAA)"].ToString();//这里不会写
这个有两种写法。
1、textBox1.Text = SDR[0].ToString();//这里不会写
2、string sql1 = "SELECT SUM(AAA) FROM O WHERE CCC = '" +123.Text.Trim()+"'";
将这个语句改为:string sql1 = "SELECT SUM(AAA) as SUMAAA FROM O WHERE CCC = '" +123.Text.Trim()+"'";
textBox1.Text = SDR["SUMAAA"].ToString();//这里不会写