MySql.Data.dll
引用
using MySql.Data;
using MySql.Data.MySqlClient;
然后使用
string strConn = "server=localhost;user id=root;password=;database=ddemo;pooling=false";
MySqlConnection objConn = new MySqlConnection(strConn);
try
{
objConn.Open();
string strSQL = "select * from `ecs_category` ";
MySqlDataAdapter myda=new MySqlDataAdapter(strSQL, objConn);
myda.Fill(ds);
objConn.Close();
}
catch (Exception ex)
{
Response.Write("Error accessing the database:" + ex.Message);
}
finally
{
objConn.Close();
}
跟mssql感觉一样。
2.dropdownlist无限分类,空格(转自http://www.cnblogs.com/chensubo/archive/2008/02/11/1067037.html)
//绑定顶级分类
9 private void BindDrpClass()
10 {
11 Bll.Class classSystem = new Bll.Class();
12 DataTable dt = classSystem.GetClassList("").Tables[0];
13 ddlClass.Items.Clear();
14 ddlClass.Items.Add(new ListItem("添加根栏目","0"));
15 DataRow[] drs = dt.Select("ParentID= " + 0);
16
17 foreach (DataRow dr in drs)
18 {
19 string classid = dr["ClassID"].ToString();
20 string classname = dr["ClassName"].ToString();
21 //顶级分类显示形式
22 classname = "╋" + classname;
23
24 ddlClass.Items.Add(new ListItem(classname, classid));
25 int sonparentid = int.Parse(classid);
26 string blank = "├";
27 //递归子分类方法
28 BindNode(sonparentid, dt, blank);
29 }
30 ddlClass.DataBind();
31 }
32 //绑定子分类
33 private void BindNode(int parentid, DataTable dt, string blank)
34 {
35 DataRow[] drs = dt.Select("ParentID= " + parentid);
36
37 foreach (DataRow dr in drs)
38 {
39 string classid = dr["ClassID"].ToString();
40 string classname = dr["ClassName"].ToString();
41
42 classname = blank + classname;
43 ddlClass.Items.Add(new ListItem(classname, classid));
44
45 int sonparentid = int.Parse(classid);
46 string blank2 = blank + "─";
47
48 BindNode(sonparentid, dt, blank2);
49 }
50 }
前导空格就在搜狗输入法中文状态全角下输入空格就ok了