2024年3月9日发(作者:)
1.很多人都在为数据库的连接发愁,下面这个是完整的过程
strSQL为你写的SQL语句,strPath为你的access数据库的位置
//Access数据库查询
public static object ExecuteAccessQuery(string strSQL, string strPath)
{
string ACCESS_CONN_STRING =
"Provider=.4.0;Data Source=" + ng() +
";User Id=admin;Password=;";
OleDbConnection conn = new
OleDbConnection(ACCESS_CONN_STRING);
OleDbCommand cmd = new OleDbCommand(strSQL, conn);
dType = ;
try
{
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
(ds);
return ds;
}
catch
{
();
throw;
}
}
//Access数据库异动(新增,修改,删除)
public static void ExecuteAccessNonQuery(string strSQL, string
strPath)
{
string ACCESS_CONN_STRING =
"Provider=.4.0;Data Source=" + ng() +
";User Id=admin;Password=;";
OleDbConnection conn = new
OleDbConnection(ACCESS_CONN_STRING);
();
OleDbCommand cmd = new OleDbCommand(strSQL, conn);
dType = ;
using (OleDbTransaction trans = ransaction())
{
ction = trans;
try
{
eNonQuery();
();
}
catch
{
ck();
throw;
}
finally
{
();
}
}
}
--------------------------------------------------------


发布评论