public DataSet RunProcReturn(string procName)
{
DataSet ds = new DataSet();
try
{
SqlDataAdapter dap = CreateDataAdaper(procName, null);
dap.Fill(ds, "tbName");
return ds;
}
catch
{
Close();
return ds;
}
}
private SqlDataAdapter CreateDataAdaper(string procName, SqlParameter[] prams)
{
Open();
SqlDataAdapter dap = new SqlDataAdapter(procName, strConn);
dap.SelectCommand.CommandTimeout = 180;
dap.SelectCommand.CommandType = CommandType.Text; //执行类型:命令文本
if (prams != null)
{
foreach (SqlParameter parameter in prams)
dap.SelectCommand.Parameters.Add(parameter);
}
return dap;
}
public void Open()
{
// 打开数据库连接
Close();
if (strConn == null)
{
strConn = new SqlConnection(connStr);
}
if (strConn.State == System.Data.ConnectionState.Closed)
strConn.Open();