日期:2014-05-17  浏览次数:20521 次

C#连接MySQL数据库问题
string connString = "server=localhost;userid=root;password=;Database=StudentTable;charset=utf8";
MySQLConnection DBconn = new MySQLConnection(connString);
try
{
      DBconn.Open();
      string sql = "insert into StudentTable(UserID,UserPWD,UserName) values('10306589','302365','maxiaotang')";
      MySQLCommand DBComm = new MySQLCommand(sql, DBconn);
//在执行下面这一句时报错,求各位大神帮忙看下问题出在哪里
      DBComm.ExecuteNonQuery();
}
catch (MySQLException e)
{
       Console.WriteLine("Error:" + e);
}
finally
{
       DBconn.Close();
}


------解决方案--------------------
明显是语法有问题嘛,你可以把最后生成的sql放到mysql看能执行不
------解决方案--------------------
明显是sql出问题了吗,直接在db中执行看看。
------解决方案--------------------
Database=StudentTable
insert into StudentTable
你这里数据库和表名是一样的么?Database这里要写数据库名字的。
------解决方案--------------------
语句问题,直接放MYSQL执行看看