C#连接mysql数据库

MySQLDriverCS.dll.添加到.net的组件
MySQLDriverCS.dll.的下载地址http://prdownloads.sourceforge.net/mysqldrivercs/MySQLDriverCS-n-EasyQueryTools-3.0.18.exe?download

MySQLDriverCS.dll使用方法
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Sql;
using System.Data;
using MySQLDriverCS;

namespace seechn
{
    class Datamysql
    {
       
        public static DataTable GetTreeViewTable(string sql)
        {
            MySQLConnection conn = null;
            string connstr = "Data Source=seechn;Password=zlk;User ID=root;Location=localhost";
            conn = new MySQLConnection(connstr);
            conn.Open();
            MySQLCommand commn = new MySQLCommand("set names gb2312", conn);
            commn.ExecuteNonQuery();
            //string sql = "select * from ClientInfo";
            MySQLDataAdapter mda = new MySQLDataAdapter(sql, conn);
            DataSet dataset = new DataSet();
            mda.Fill(dataset);
            mda.Dispose();
            conn.Close();
            return dataset.Tables[0];

        }
    }
}

posted on 2007-05-04 11:33  恋上你的笑  阅读(187)  评论(0)    收藏  举报

导航