Pages

Showing posts with label Passing parameter to SQL store procedure. Show all posts
Showing posts with label Passing parameter to SQL store procedure. Show all posts

Tuesday, 11 March 2014

Passing parameter to store procedure using command parameter in MVC4

public DataTable getEdgingReport(DateTime date)
{
DataTable dt;
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand("SpFpcGenerateEdgingReport", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@rights_fromdate", DateTime.Now);
cmd.Parameters.AddWithValue("@rights_todate", date);
try
{
SqlDataAdapter ad = new SqlDataAdapter();
con.Open();
ad.SelectCommand = cmd;
ad.Fill(ds);
dt = ds.Tables[0];
return dt;
}
catch
{
con.Close();
con.Dispose();
SqlDataAdapter ad = new SqlDataAdapter();
con.Open();
ad.SelectCommand = cmd;
ad.Fill(ds);
dt = ds.Tables[1];
return dt;
//return result;
}
finally
{
con.Close();
con.Dispose();
}
}
}