Experience in accessing MySQL Databases in. NET

Source: Internet
Author: User
In. NET, many users use the official MySQL database. NETconnector, of course, you can also find yourself using it on the relevant website. The following articles mainly describe.. NET experience in accessing MySQL databases. Some experience has been accumulated during use: 1). NET Access to MySQL database experience: Using Parameter Parameters

In. NET, many users use the official MySQL database. NET ctor, of course, you can also find yourself using it on the relevant website. The following articles mainly describe.. NET experience in accessing MySQL databases. Some experience has been accumulated during use: 1). NET Access to MySQL database experience: Using Parameter Parameters

In. NET, many users use the official MySQL database. NET ctor, of course, you can also find yourself using it on the relevant website. The following articles mainly describe.. NET experience in accessing MySQL databases.

I have accumulated some experience in usage:

1). NET experience in accessing MySQL Databases: When submitting commands using Parameter parameters, you must replace the "@" number "? "No., this makes me confused for a day, but I just don't understand why MySQL is special, such as MS, ODP. NET for Oracle, OleDb, etc.

Use.

Example:

 
 
  1. string connstr=Setting.Instance().GetConnectionString("MySQL");
  2. MySQLConnection conn =new MySQLConnection(connstr);
  3. conn.Open();
  4. string query = "insert into myfirst(Id,Name) values(?Id,?Name)";
  5. MySQLCommand cmd = new MySQLCommand(query, conn);
  6. MySQLParameter para1=new MySQLParameter("?Id",DbType.Int32);

What should I do here? No.

 
 
  1. MySQLParameter para2=new MySQLParameter("?Name",DbType.String);

What should I do here? No.

 
 
  1. para1.Value=5;
  2. para2.Value="ddd";
  3. cmd.Parameters.Add(para1);
  4. cmd.Parameters.Add(para2);
  5. cmd.ExecuteNonQuery();

2 ). NET Access to MySQL database experience: MySQL also has reserved words. In order to provide compatibility, I must find the delimiters. It is hard to find them in the MySQL Forum. The delimiter used is ', this symbol is not a single quotation mark, but the "point" in front of number 1 on the keyboard. It really kills me.

3). NET experience in accessing MySQL Databases: The TOP function in MySQL is very simple. You only need to use "limit n" after the statement, which is much more convenient than the Rownum in ORACLE.

Using MySQL. NET ctor to access MySQL is not bad in general. Most of them are compatible with IConnection and ICommand in. NET.

PS: I don't know whether to provide a MySQLDateTime class in. NET Connector. I don't know how to use this class and how to use it. I have not found any relevant materials in China. MySQLDateTime and System. Date are not compatible yet. There are more than N related posts on the MySQL forum.

If the DateTime Field passed to MySQL using the String type Parameter, the following error is reported: Unable to Convert MySQL Date/Time value to System. DateTime.

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.