引用 MySQL使用基于Parameter方式代码,总是提示:“Column '列名' cannot be null”

来源:互联网 发布:vb 校验ip格式 编辑:程序博客网 时间:2024/05/21 21:50

MySQL使用基于Parameter方式代码,总是提示:“Column '列名' cannot be null”

MySQL使用基于Parameter方式代码,总是提示:“Column '列名' cannot be null”

MySQL使用基于Parameter方式代码,总是提示:“Column '列名' cannot be null”

解决方法1:直接在连接字符串里面加一个 oldsyntax=true  即可。

例如:server=127.0.0.1;user id=root;password=;database=itemdb;oldsyntax=true

解决方法2:将语句中的 @ 替换为 ?

例如:

StringBuilder strSql=new StringBuilder();

strSql.Append("insert into test(");

strSql.Append("name)");

strSql.Append(" values (");

strSql.Append("?name)");

MySqlParameter[] parameters = {

  new MySqlParameter("?name", MySqlDbType.VarChar,45)};

parameters[0].Value = model.name;

DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);

 

源文来自:http://fighter2038.blog.163.com/blog/static/95802350201051321817913/

原创粉丝点击