操作sql数据库的。如果是access,换成 oledb
string sConnectionString= "数据库连接";
SqlConnection objConn= new SqlConnection(sConnectionString);
objConn.Open();
SqlDataAdapter da= new SqlDataAdapter("sql语句", objConn);
DataSet ds = new DataSet();
da.Fill(ds);
objConn.Close();
亲,用Command对象创建DataAdapter对象,再用DataAdapter的Fill方法将CommandText的查询结果填充到DataSet中。代码示例如下:
SqlCommand cmd = new SqlCommand();
cmd.CommandText ="select * from table_admin";
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet db = new DataSet();
adp.Fill(db,"MyTable");
string sql = "你的语句";
string connection = "你的连接字符串";
DataSet resultData = new DataSet();
using (SqlDataAdapter adapter = new SqlDataAdapter(sql, connection))
{
try
{
adapter.Fill(resultData);
}
catch (Exception)
{
}
}
//resultData已经获取过你要的结果了