VS 2005 连接MYSQL

方法一
1.http://ftp.ntu.edu.tw/pub/MySQL/Downloads/Connector-Net/
  依次安装 mysql-connector-net-5.0.9.exe 和 MySQL.VisualStudio.msi
2 添加引用 MySql Data
3 using MySql.Data.MySqlClient;
Code

            MySqlConnection myConn = new MySqlConnection(connStr);
            myConn.Open();
            MySqlCommand cmd 
= myConn.CreateCommand();
            
string sql = "select * from make_view limit 0,2";
            cmd.CommandText 
= sql;
            MySqlDataAdapter mda 
= new MySqlDataAdapter();
            mda.SelectCommand 
= cmd;
            DataSet ds 
= new DataSet();
            mda.Fill(ds);
            dataGridView1.DataSource 
= ds.Tables[0];
            myConn.Close();
方法二
http://sourceforge.net/projects/mysqldrivercs/
MySQLDriverCS-n-EasyQueryTools-4.0.1-DotNet2.0.exe
在安装文件夹下面找到MySQLDriver.dll,然后将MySQLDriver.dll添加引用到项目中
using MySQLDriverCS;
Code

            DataSet dataSet = frmMDI.MySql.query("select * from view1 order by name");
            cBoxMake.Items.Clear();
            foreach (DataRow row in dataSet.Tables[0].Rows)
            {
                cBoxMake.Items.Add(row[1]);
            }
            gridLookUpEdit1.Properties.DataSource = dataSet.Tables[0];
         }
posted @ 2009-07-27 19:09  幽灵湖  阅读(304)  评论(0)    收藏  举报