Hi everyone-
I have following code:
SqlConnection conn =
new SqlConnection(xyz);
SqlCommand myCommand =
new SqlCommand();
myCommand.CommandType = System.Data.CommandType.Text;
myCommand.Connection = conn;
sSQL =
"SELECT * FROM abc WHERE abcID <> 26 ";
if (current.Request["lmn"] != null && current.Request["lmn"] != "")
{
SqlParameter parameterlmn =
new SqlParameter("@lmn", SqlDbType.NVarChar, 50);
parameterlmn .Value =
"'" + current.Request["lmn"] + "'";
myCommand.Parameters.Add(parameterlmn);
sSQL +=
" AND lmn LIKE @lmn ";
}
myCommand.CommandText = sSQL;
SqlDataAdapter myAdapter =
new SqlDataAdapter(myCommand);
conn.Open();
DataSet ds = new DataSet();
myAdapter.Fill(ds,
"Products");
conn.Close();
myAdapter.Dispose();
return ds;
The problem is when i return that dataset ds, its giving me following error :
System.Data.SqlClient.SqlException: Must declare the variable '@lmn'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
Any ideas???