110,538
社区成员
发帖
与我相关
我的任务
分享
public DataSet GetListWithProcedure(string strProcedureName, SqlParameter[] paras)
{
DataSet ds = new DataSet();
try
{
using (SqlConnection conn = new SqlConnection(stsqlcon))
{
using (SqlCommand command = new SqlCommand(strProcedureName, conn))
{
command.CommandType = CommandType.StoredProcedure;
for (int i = 0; i < paras.Length; i++)
{
command.Parameters.Add(paras[i]);
}
SqlDataAdapter da = new SqlDataAdapter(command);
da.Fill(ds, "ds");
return ds;
}
}
}
catch
{
throw;
}
}
public DataSet GetListWithProcedure(string strProcedureName, params SqlParameter[] paras)
{
DataSet ds = new DataSet();
try
{
using (SqlConnection conn = new SqlConnection(stsqlcon))
{
using (SqlCommand command = new SqlCommand(strProcedureName, conn))
{
command.CommandType = CommandType.StoredProcedure;
if(paras != null)
{
for (int i = 0; i < paras.Length; i++)
{
command.Parameters.Add(paras[i]);
}
}
SqlDataAdapter da = new SqlDataAdapter(command);
da.Fill(ds, "ds");
return ds;
}
}
}
catch
{
throw;
}
}
调用
DataTable dt = DBHelpSQL.GetListWithProcedure("sp_who_lock",null);
this.DgvPidData.DataSource = dt;
public DataSet GetListWithProcedure(string strProcedureName, SqlParameter[] paras)
{
DataSet ds = new DataSet();
try
{
using (SqlConnection conn = new SqlConnection(stsqlcon))
{
using (SqlCommand command = new SqlCommand(strProcedureName, conn))
{
command.CommandType = CommandType.StoredProcedure;
if(paras!=null&¶s.Length>0) { for (int i = 0; i < paras.Length; i++)
{
command.Parameters.Add(paras[i]);
}}
SqlDataAdapter da = new SqlDataAdapter(command);
da.Fill(ds, "ds");
return ds;
}
}
}
catch
{
throw;
}
}
加上判断