Hi,
I used to use the following function of my DB Layer class when i was not using Patterns & Practices. I hope this helps.
public static DataSet GetDataSetFromSP(string spName, SqlParameter[] paramArr)
{
SqlConnection Connection = new SqlConnection();
try
{
Connection.ConnectionString = ConfigurationManager.ConnectionStrings["TestDB"].ConnectionString
Connection.Open();
SqlCommand oCmd = new SqlCommand();
oCmd.Connection = Connection;
oCmd.CommandText = spName;
oCmd.CommandType = CommandType.StoredProcedure;
if (paramArr != null)
{
foreach (SqlParameter sqlParam in paramArr)
{
oCmd.Parameters.Add(sqlParam);
}
}
SqlDataAdapter oAdp = new SqlDataAdapter(oCmd);
DataSet ds = new DataSet();
oAdp.Fill(ds);
return ds;
}
catch (Exception E)
{
throw new Exception(E.Message);
}
finally
{
if (Connection.State != ConnectionState.Closed) Connection.Close();
Connection.Dispose();
}
}
/// Usuage
DataSet Ds;
SqlParameter[] sqlParam = new SqlParameter[2];
sqlParam[0] = new SqlParameter("@ID", Convert.ToInt32(Session["ID"]));
sqlParam[1] = new SqlParameter("@ContentType", TxtContent.Txt);
Ds = DBHelper.GetDataSetFromSP("spGetContentByID", sqlParam);