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

C#连接MYSQL问题,帮忙看一下。
MySQLConnection conn = null;

  conn = new MySQLConnection(new MySQLConnectionString("localhost", "bishe", "root", "sa").AsString);

  conn.Open();

  string h11 = "select * from table1 where id = '"+uid+"'";
  MySQLCommand commn = new MySQLCommand(h11, conn);

  int count = (int)commn.ExecuteScalar();
  if (count == 1)
  {
  MessageBox.Show("存在该账号!");
  }
  else
  {
  MessageBox.Show("不存在该账号。");
  this.Close();
  }
  commn.ExecuteNonQuery();



出现问题:
 int count = (int)commn.ExecuteScalar();未将对象引用设置到对象的实例
如何解决啊。

------解决方案--------------------
不存在时,没有存在的行,所以你是取不到数据的,也没所谓转化为int,
------解决方案--------------------
int count = int.Parse(commn.ExecuteScalar().Tostring());