This article mainly describes. the following is an example of the core issue in this article, we hope you will gain some benefits after browsing.
In. NET to access the MySQL database, I use the official MySQL. NET ctor, 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 database 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);
What should I do here? No.
- MySQLParameter para2=new MySQLParameter("?Name",DbType.String);
What should I do here? No.
- para1.Value=5;
- para2.Value="ddd";
- cmd.Parameters.Add(para1);
- cmd.Parameters.Add(para2);
- cmd.ExecuteNonQuery();
2) There are also reserved words in the MySQL database. 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 databases 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 database problems can go to: http://forum.MySQL.com/forum to see :)
Original article title: experience in accessing MySQL database in. NET!
Connection: http://www.cnblogs.com/tintown/archive/2005/11/08/271646.html