Error Not Declaring Scalar Variable

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
N

news.microsoft.com

I get an error on the variable @ObjectName. Can anyone suggest what is
wrong?

_name = _lvi.Text;

_type = "T";

_sql = "INSERT INTO QueryBuilderTableViews(ObjectName,ObjectType) VALUES " +

" (@ObjectName, @ObjectType)";

cmd.CommandText = _sql;

cmd.Parameters.AddWithValue("@ObjectName", _name); //
error on this line.

cmd.Parameters.AddWithValue("@ObjectType", _type);

cmd.ExecuteNonQuery();



Thanks

Bill
 
news.microsoft.com said:
I get an error on the variable @ObjectName. Can anyone suggest what is
wrong?

_name = _lvi.Text;

_type = "T";

_sql = "INSERT INTO QueryBuilderTableViews(ObjectName,ObjectType) VALUES "
+

" (@ObjectName, @ObjectType)";

cmd.CommandText = _sql;

cmd.Parameters.AddWithValue("@ObjectName", _name);
// error on this line.

cmd.Parameters.AddWithValue("@ObjectType", _type);

cmd.ExecuteNonQuery();



Thanks

Bill
Please quote the entire text of the error message and the source code line
cited.
 
What is wrong is not having thought that the error message could help to
diagnose the problem ;-)
 
Sorry about that. The error message is that saying that I need to declare
the scalar variable @ObjectName. I thought that I did that in the sql
statement.
 
It looks like a provider side error. Which provider are you using ? Your
provider may :
- not support named parameters
- doesn't use the SQL Server convention
- or perhaps should you not add the prefix char for your provider

What is the underlying db and the provider used ?
 
Back
Top