Performed with the query set, there are input and output parameters of the stored procedure

/// <Summary>
/// execute a stored procedure, query data
/// </ Summary>
/// <param name = "para"> </ param>
/// <param name = "CommandText"> </ param>
/// <Returns> </ Returns>
public static GetDataSetByStoredProcedure the DataSet (the SqlParameter [] para, CommandText String)
{

para[11].Direction = ParameterDirection.Output;
using (SqlConnection sqlconn = new SqlConnection(strConn))
{
try
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlconn;
cmd.CommandText = commandtext;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddRange(para);
sqlconn.Open();

SqlDataAdapter dp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
// 填充dataset
dp.Fill(ds);

string result = para[11].Value.ToString();
return ds;
}
catch (Exception ex)
{
return null;
}
finally
{
sqlconn.Close();
}
}
}

Guess you like

Origin www.cnblogs.com/simoncheung/p/11910207.html