Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 .NET Inside SQL Server (2005)
 sqlparameter

Author  Topic 

samir80
Starting Member

10 Posts

Posted - 2008-07-10 : 17:59:53
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???

   

- Advertisement -