When MySQL is referenced using the Parameter-based code, the following message is always displayed: "Column 'column name' cannot be null ".

Source: Internet
Author: User

When using the Parameter-based code to reference MySQL, the following message is always displayed: "Column 'column name' cannot be null" to solve the problem of using the Parameter-based code in MySQL: solution 1: add an oldsyntax = true to the connection string. For example:

Server = 127.0.0.1; user id = root; password =; database = itemdb; oldsyntax = true

 

Solution 2: replace @? For example:
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 );

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.