1
l我使用数据应用程序块进行大部分数据访问,特别是使用SqlHelper类调用ExecuteReader,ExecuteNonQuery等方法。每个数据库调用传递连接字符串。从Microsoft数据应用程序块连接到MySQL
我该如何修改这个以启用与MySQL数据库的连接。
l我使用数据应用程序块进行大部分数据访问,特别是使用SqlHelper类调用ExecuteReader,ExecuteNonQuery等方法。每个数据库调用传递连接字符串。从Microsoft数据应用程序块连接到MySQL
我该如何修改这个以启用与MySQL数据库的连接。
如果你已经安装了企业库并且已经知道如何连接到SQL Server数据库,那么连接到MySQL数据库并不困难。
一种方法是使用ODBC。这是我做的:
public List<Contact> Contact_SelectAll() { List<Contact> contactList = new List<Contact>(); Database db = DatabaseFactory.CreateDatabase("MySqlDatabaseTest"); DbCommand dbCommand = db.GetSqlStringCommand("select * from Contact"); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { Contact contact = new Contact(); contact.ID = (int) dataReader["ContactID"]; client.FirstName = dataReader["ContactFName"].ToString(); client.LastName = dataReader["ContactLName"].ToString(); clientList.Add(client); } } return clientList; }
另一种方式来做到这一点是建立和使用MySQL提供商。 This guy did that。 我学会了如何通过adapting these instructions来连接到Access。 Oh, and here are some more MySql Connection String samples。