vs2013中c#如何连接MySQL数据库。
1个回答
推荐于2016-09-28 · 知道合伙人互联网行家
关注
展开全部
public static string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("~") + "数据库文件路径";
public System.Data.OleDb.OleDbConnection strconn = null;
//获取datatable数据
public DataTable AExcuToTable(string sql)
{
DataTable dv = null;
// System.Data.OleDb.OleDbConnection strconn=null;
try
{
strconn = new System.Data.OleDb.OleDbConnection(strConnection);
if (strconn.State == ConnectionState.Closed)
strconn.Open();
System.Data.OleDb.OleDbDataAdapter oa = new System.Data.OleDb.OleDbDataAdapter(sql, strconn);
System.Data.DataSet ds = new DataSet();
oa.Fill(ds, "Table");
dv = ds.Tables["Table"];
}
catch
{
return null;
}
strconn.Close();
return dv;
}
public System.Data.OleDb.OleDbConnection strconn = null;
//获取datatable数据
public DataTable AExcuToTable(string sql)
{
DataTable dv = null;
// System.Data.OleDb.OleDbConnection strconn=null;
try
{
strconn = new System.Data.OleDb.OleDbConnection(strConnection);
if (strconn.State == ConnectionState.Closed)
strconn.Open();
System.Data.OleDb.OleDbDataAdapter oa = new System.Data.OleDb.OleDbDataAdapter(sql, strconn);
System.Data.DataSet ds = new DataSet();
oa.Fill(ds, "Table");
dv = ds.Tables["Table"];
}
catch
{
return null;
}
strconn.Close();
return dv;
}
追问
需不需要下载什么文件的???
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询