/// <summary> /// 创建结果集对象--静态方法 /// </summary> /// <param name="sql">sql语句</param> /// <param name="sp">参数数组</param> /// <returns>DataSet结果集</returns> public static DataSet SCreateDataSet(string sql, SqlParameter[] sp) { DBSql dsSql = new DBSql(); try { dsSql.dataadapter = dsSql.CreateDataAdapter(sql); if (sp != null) { for (int i = 0; i < sp.Length; i++) { dsSql.dataadapter.SelectCommand.Parameters.Add(sp[i]);//将参数加到Command中 } } dsSql.dataset = new DataSet(); dsSql.dataadapter.Fill(dsSql.dataset); } catch (Exception ex) { throw ex; } finally { dsSql.CloseDataReader(); dsSql.CloseConnection(); } return(dsSql.dataset); }
/// <summary> /// 创建结果集对象--静态方法 /// </summary> /// <param name="sql">sql语句</param> /// <returns>DataSet对象</returns> public static DataSet SCreateDataSet(string sql) { DBSql dsSql = new DBSql(); try { dsSql.dataadapter = dsSql.CreateDataAdapter(sql); dsSql.dataset = new DataSet(); dsSql.dataadapter.Fill(dsSql.dataset); } catch { return(null); } finally { dsSql.CloseDataReader(); dsSql.CloseConnection(); } return(dsSql.dataset); }