Tragedy: the first time Mysql was used

Source: Internet
Author: User

I haven't written a program for a long time. I am ready to start work. I have to use databases in some places. After careful consideration, I still want to use open-source MySql. Although MSSQL and Access are good, however, I have heard of the great names and advantages of Mysql, but I have no chance to use it. So I also want to take this opportunity to study hard.

The simple process of creating a database and a table is almost the same, and it is quite smooth. Although it is an English interface, it is acceptable. Next, I encountered a lot of trouble in operating the database through C. An error is always prompted during data insertion. It cannot be blank. However, if debugging finds that all data values exist, how can this happen .. When I was wondering, I thought it might be about character sets, and my field names all use Chinese. Google also found a lot of character set problems, so I re-built the table and failed the test. The prompt "Column 'column name' cannot be null" is displayed. This time it was in English, at the beginning are some garbled, still can not solve the problem, and go to google, this time found that someone and I have the same problem, and the following article also describes the correct method: http://bybaxiao.blog.163.com/blog/static/309761232009321102523527/

This is the reason for confirmation after debugging:

MySQL uses the Parameter-based code and always prompts: "Column 'column name' cannot be null"

MySQL uses the Parameter-based code and always prompts: "Column 'column name' cannot be null"

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

It took me three hours to finally solve the problem.

 

 

Programmers are interested in. NET software development, Matlab programming, and network technology.

Welcome to my Cnblog blog: http://www.cnblogs.com/asxinyu/

Welcome to exchange, QQ: 1287263703; MSN: dong.binhui@hotmail.com

E-mail: asxinyu@qq.com, asxinyu@126.com

 

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.