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???
Satish KathiPosted Jul 11, 2008, 10:26 AM
When you are passing value to the SQLParameter you don’t need quotes
parameterlmn .Value = current.Request["lmn"];
But this won’t throw error(not an error) but the output from the SQL will change
Except the above change your code is working fine and it is returning DataSet.
AhmadPosted Jul 11, 2008, 5:29 AM