急啊,请问一个SqlDataReader和主键问题
using (SqlConnection conn = new SqlConnection(conStr))
{
conn.Open();
SqlCommand cmd = new SqlCommand("select * from Users where UserID=@UserID", conn);
cmd.Parameters.AddRange(paras);//加入参数
SqlDataReader dr = cmd.ExecuteReader();//通过CMD对象获取数据
DataTable dt = new DataTable();
dt.Load(dr);
conn.Close();//必须放到最后关闭
return dt;
}
protected DataSet ExecuteDataSet(DbCommand cmd)
{
DbDataAdapter dbDataAdapter = dbfactory.CreateDataAdapter();
dbDataAdapter.SelectCommand = cmd;
DataSet ds = new DataSet();
dbDataAdapter.Fill(ds);
return ds;
}