日期:2014-05-18  浏览次数:20994 次

求教,label.text 赋值无法显示
求教各位大侠,下列代码中将数据库中 总价 列 求和后 赋值给 label2.text ,form框体上数值无法显示。求帮忙看看哪里有问题
  private void label2_Click(object sender, EventArgs e)
  {
  OleDbConnection conn = new OleDbConnection();
  String str = "./db1.mdb";
  OleDbConnection OleDbcon = new OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;Data Source=" + str + ";User ID=admin;Password=;Jet OLEDB:Database Password=");
  OleDbcon.Open();  

  OleDbCommand cmd = new OleDbCommand();
  cmd.Connection = OleDbcon;
  string s = label2.Text;
  string select = String.Format("SELECT 总价 FROM sheet1 union all SELECT sum(总价) FROM sheet1", s);
  cmd.CommandText = select;
  OleDbDataReader reader = cmd.ExecuteReader();
  reader.Read();
  label2.Text = reader.GetString(0);
  }





------解决方案--------------------
if(reader.Read())
{
label2.Text = reader.GetString(0);
}
------解决方案--------------------
跟一下代码,这种事情,基本上都是因为你的sql没有读到结果!
目测,是因为你的sql问题!
------解决方案--------------------
label2.Text = reader[0].ToString();