只需要 sqlDA.Fill(dataSet);不要传入datatable参数即可
/// <summary>
/// 执行存储过程,返回多个DataTable结果集
/// </summary>
/// <param name="storedProcName">存储过程名</param>
/// <param name="parameters">存储过程参数</param>
/// <param name="tableName">DataSet结果中的表名</param>
/// <returns>DataSet</returns>
public static DataSet RunProcedureReturnMoreDateTable(string storedProcName, IDataParameter[] parameters)
{
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
DataSet dataSet = new DataSet();
connection.Open();
SqlDataAdapter sqlDA = new SqlDataAdapter(storedProcName, connection);
sqlDA.SelectCommand = BuildQueryCommand(connection, storedProcName, parameters);
sqlDA.Fill(dataSet);
connection.Close();
return dataSet;
}
}
/// <summary>
/// 执行存储过程
/// </summary>
/// <param name="storedProcName">存储过程名</param>
/// <param name="parameters">存储过程参数</param>
/// <param name="tableName">DataSet结果中的表名</param>
/// <returns>DataSet</returns>
public static DataSet RunProcedure(string storedProcName, IDataParameter[] parameters, string tableName)
{
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
DataSet dataSet = new DataSet();
connection.Open();
SqlDataAdapter sqlDA = new SqlDataAdapter();
sqlDA.SelectCommand = BuildQueryCommand(connection, storedProcName, parameters);
if (tableName == "")
{
/*
* 返回多个DataTable结果集
* string result = "";
* DataSet ds = GetRecordByPageOrder.GetList("vw_ShopAspnetUser", "ShopId", pageSize, pageIndex, "*", strWhere, "CreateDate desc,ShopTitle asc");
* result = Json.DataTableToJSON(ds.Tables[0], "ShopAspnetUser");
* result += Json.DataTableToJSON(ds.Tables[1], "total");
* result = result.Replace("}{", ",");
* Response.Write(result);
*/
sqlDA.Fill(dataSet);
}
else
{
sqlDA.Fill(dataSet, tableName);
}
connection.Close();
return dataSet;
}
}