首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#连接MYSQL有关问题,帮忙看一下

2012-05-27 
C#连接MYSQL问题,帮忙看一下。MySQLConnection conn nullconn new MySQLConnection(new MySQLConnecti

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());

热点排行