One: referencing mysql using parameter-based code, always prompt: "column name ' cannot be null" resolves
MySQL uses parameter-based code, and always prompts: "Column name ' cannot be null" Workaround 1: Add a oldsyntax=true directly inside the connection string. For example:?
1 |
server=127.0.0.1; user id=root; password =; database =itemdb;oldsyntax= true |
Workaround 2: Replace the @ in the statement with the? For example:?
1 2 3 4 5 6 7 8 9 Ten One A - - the - - |
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); |
Two: parameter parameter setting when using ODBC to link MySQL
When using ODBC link MySQL, @Parameter set the SQL parameters but found that the value can not be communicated to the database, the original MySQL is specialized with the number. Online talk? Parameter instead of @parameter, but tried or not, and finally concluded that the direct use of the number is good, the following is an example:
INSERT INTO table_name (NAME,INTRO) VALUES (?,?)
Cmd. Parameters.Add ("1", "value1");
Cmd. Parameters.Add ("2", "value2");
Since the parameter parameter is all the number, then the parameter values can only be set in order, not as @parameter as the key-value pairs.
If the operation is different when using mysqlcontector .... is the first way.
Some points to note when developing MySQL database programs in C #