MilesMorales MilesMorales - 8 days ago 5
C# Question

DataContext.ExecuteQuery parameter issues

I get the following error:

Procedure or function 'procTestReport' expects parameter '@StartDate',
which was not supplied.

When I execute the following code:

String[] args = new String[2]{StartDate.ToShortDateString(), EndDate.ToShortDateString()};

lst = dbContext.ExecuteQuery<Summary>("procTestReport", args).ToList<Summary>();

Are the arguments I pass supposed to be presented in a different way? From the following link it seems like I'm using it correctly:


If you need execute a store procedure you can use instead:

SqlConnection con = new SqlConnection("your ConnectionString");

SqlCommand cmd = new SqlCommand("your SP_Name", con);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("param name", "param value"));
cmd.Parameters.Add(new SqlParameter("param2 name", "param2 value"));
SqlDataReader reader = cmd.ExecuteReader();

SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();

return dt;

dt contains the return of store procedure

if is necesary to use LinQ, try this

dataContext.ExecuteCommand("EXEC usp_SomeProcedure {0}, {1}, {2}", param1, param2, param3);