Since last year, I have been using LINQ. I don't want to change it because of convenience ..
Recently, the website needs to insert data into MySQL, but the built-in LINQ of vs2008 does not support MySQL.
After finding some information on the Internet, I finally found a MySQL-supported LINQ tool, which is dblinq. Post the method for later use.
I. tools:
Dblinq;
MySQL 5.0 or above, the programming host needs to be installed;
Vs2008
Ii. Generate the datacontext CS File
Dbmetal.exe-provider = mysql-Database: mydatebase-server: you host computer-user: MySQL user-Password: You PWD-namespace: mysqllinq-code: mysqllinq. CS-sprocs
// Note that the namespace is mysqllinq, and-sprocs must
3. Put the file datacontext cs into the project file
Note: Put the CS file in the first layer of the project, such as app_code, or in the internal library.
Using dblinq. LINQ;
Using dblinq. LINQ. Mapping;
(If it is not in app_code, add reference here)
4. Create a class project dalmysql in vs 2008 and add references
Dblinq. dll;
Dblinq. MySQL. dll;
MySQL. Data. dll;
// The above three can be found in DbLinq-0.18 \ build.
System. Data. LINQ. dll;
// In c: \ Program Files \ reference assemblies \ Microsoft \ framework \ v3.5 \ system. Data. LINQ. dll
// This is a reference !!!
5. Add a web_app project and reference dalmysql Project
6. Add a reference on the Aspx. CS page:
Using mysql. data;
Using mysql. Data. mysqlclient;
Using mysqllinq; // namespace of the datacontext CS File
// Omitted
String connstr = @ "Server = localhost; database = test; user = root; Pwd = ikmb; Port = 3306 ";
Mysqlconnection conn = new mysqlconnection (connstr );
Test T = new test (conn );
VaR DATA = from F in T. users select F;
Gridview1.datasource = data;
Gridview1.databind ();
Finally, download the package for dblinq.