Some points to note when developing MySQL database programs in C #

Source: Internet
Author: User
Tags odbc

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;userid=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 #

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.