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