怕忘了 后天就比赛了 存着随时看下
//查询数据集 public DataSet Query(string sqlStr) { using (SqlConnection conn = new SqlConnection(constr)) { using (SqlDataAdapter ada = new SqlDataAdapter(sqlStr, conn)) { conn.Open(); DataSet ds = new DataSet(); ada.Fill(ds); return ds; } } } //查询datatable public DataTable GetQueryData(string sqlStr) { DataSet ds = Query(sqlStr); if (ds != null && ds.Tables.Count > 0) return ds.Tables[0]; return null; } //单个查询返回string public string GetSingle(string sqlStr) { using (SqlConnection conn = new SqlConnection(constr)) { SqlCommand cmd = new SqlCommand(sqlStr, conn); conn.Open(); return String.Format("{0}", cmd.ExecuteScalar()); } }