Some experience when accessing MySQL database in. net!

Source: Internet
Author: User
To access MySql in. net, I use the. NET connector officially provided by MySQL, this driver only needs to download to use: http://dev.mysql.com/downloads/connector/net/1.0.html

I have accumulated some experience in usage:
1) Replace "@" "? "No., this makes me confused for a day, but I just don't understand why MySQL is special, such as MS and ODP. net for Oracle, oledb, and other methods, all use the "@" number.
Example:

String connstr = Setting. instance (). getconnectionstring ("MySQL ");
Mysqlconnection conn = new mysqlconnection (connstr );
Conn. open ();
String query = "insert into myfirst (ID, name) values (? ID ,? Name )";
Mysqlcommand cmd = new mysqlcommand (query, Conn );
Mysqlparameter para1 = new mysqlparameter ("? ID ", dbtype. int32); // must be used here? No.
Mysqlparameter para2 = new mysqlparameter ("? Name ", dbtype. String); // must be used here? No.
Para1.value = 5;
Para2.value = "DDD ";
Cmd. Parameters. Add (para1 );
Cmd. Parameters. Add (para2 );
Cmd. executenonquery ();

2) reserved words are also available in MySQL. To provide compatibility, I must find the delimiters. It is hard to find them in the MySQL Forum. The Delimiter is ', which is not a single quotation mark, it's the "point" in front of number 1 on the keyboard. It's killing me.

3) 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.

All related MySQL questions can go to: http://forum.mysql.com/forum to see :)

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.