I am attempting to execute an SQL Command through a 'using' code block, but can't seem to get it to work with Parameters. I get the error: 'Parameters does not exist in the current context', does anyone have a possible solution for this problem? Heres My code:
DataTable dt = new DataTable();
using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
using (var cmd = new SqlCommand(" SELECT FName" +
" FROM EmployeeTable " +
" WHERE EmployeeId = @empId",
con)
{
Parameters.Add(new SqlParameter("@empId",empId))
})
{
try
{
con.open();
dt.Load(cmd.ExecuteReader());
}
catch(Exception ex)
{
//(snip) Log Exceptions
}
}
return dt;
See Question&Answers more detail:os