I have a method which takes a single string parameter (ID).
I want to use SqlCommand to return a DataTable of results from a query. I'm trying to call a table function from my database (Sql Server) in the query and pass in my ID parameter. The contents of this DataTable will then populate a Combobox. Here's what I have so far...
public string populateCompanyTransSellingEntityLookUp(string BlockId)
{
string _sql = "";
SqlCommand _comm = new SqlCommand();
_comm.Parameters.AddWithValue("(@block_id", BlockId);
_comm.CommandText = "SELECT [name] FROM dbo.fnGetBlockCompanyWIList(@block_id) ORDER BY [name]; ";
_comm.Connection = _conn;
_comm.CommandTimeout = _command_timeout;
DataTable dt = new DataTable();
try
{
SqlDataReader myReader = _comm.ExecuteReader();
dt.Load(myReader);
}
catch (Exception)
{
throw;
}
Combo.DataSource = dt;
return _sql;
}
But i'm getting a error, "Must declare scalar variable '@block_id'". why?