Calling SQL functions and stored-procedures with parameter in ASP .net

Stored Procedure Call with parameter

String SqlString = "sp_TabulationSheetDeptTermWise";
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection(ConString);
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = SqlString;
cmd.Parameters.AddWithValue("@TermId", ddlTermId.Text);
cmd.Parameters.AddWithValue("@QuoteVariable", "'");
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();

Function Call with parameter

string qs = "select dbo.fn_BacklogCourse(" + Session["StudentId"].ToString() + ",'" + Session["DepartmentId"].ToString() + "')";
DataSet ds = new DataSet();
ds = ClsCommon.GetAdhocResult(qs);
DataTable dt = new DataTable();
dt = ds.Tables[0];
divBacklogCourse.InnerHtml = "Your Backlog Course(s): " + dt.Rows[0][0].ToString();
catch (Exception ex)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s