c#oledbconnection连接数据库后怎么执行sql语句
2个回答
2016-06-08
展开全部
public DataTable QueryDataTable(string queryStr)
{
DataTable dt = new DataTable();
OleDbConnection conn = new OleDbConnection(ConnectionString);
OleDbDataAdapter adp = new OleDbDataAdapter(queryStr, conn);
conn.Open();
adp.Fill(dt);
conn.Close();
return dt;
}
// 方法体的部分内容
DBCommon db = new DBCommon();
DataTable dt = new DataTable();
OleDbConnection conn = new OleDbConnection(db.ConnectionString);
OleDbCommand cmd = new OleDbCommand(countSql, conn);//查询数据总数,用于分页
OleDbDataAdapter adp = new OleDbDataAdapter(sqlStr, conn);
conn.Open();
var rs = cmd.ExecuteScalar().ToString();//解决直接强制转换为int时出错的问题。
count = Int32.Parse(rs);
adp.Fill(PageSize * (PageIndex - 1), PageSize, dt);
conn.Close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询