N
Nadeem
Hi,
I have a very simple SQL query I'm trying to run against SQL Server
2000. Here is the code:
Cmd.CommandText = "update Table set Field=@Field where RecID=@RecID";
Cmd.Parameters.Add("Field", SqlDbType.Bit);
Cmd.Parameters.Add("RecID", SqlDbType.Int);
Cmd.Parameters["Field"].Value = 0;
Cmd.Parameters["RecID"].Value = 1;
Cmd.ExecuteNonQuery();
I get an exception:
System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near
'Field'.
Must declare the variable '@Field'.
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at ....
--- End of inner exception stack trace ---
I look at the SQL Trace, and se the folowing query being submitted:
exec sp_executesql N'update Table set Field=Field where RecID=@RecID',
N'Field bit,RecID int', Field = 0, RecID = 1
Everything looks fine, the variable 'Field' seems to be getting
defined, but the query doesn't execute!
Any suggestions would be appreciated. This is so simple, I must be
missing something!
Thanks!
I have a very simple SQL query I'm trying to run against SQL Server
2000. Here is the code:
Cmd.CommandText = "update Table set Field=@Field where RecID=@RecID";
Cmd.Parameters.Add("Field", SqlDbType.Bit);
Cmd.Parameters.Add("RecID", SqlDbType.Int);
Cmd.Parameters["Field"].Value = 0;
Cmd.Parameters["RecID"].Value = 1;
Cmd.ExecuteNonQuery();
I get an exception:
System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near
'Field'.
Must declare the variable '@Field'.
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at ....
--- End of inner exception stack trace ---
I look at the SQL Trace, and se the folowing query being submitted:
exec sp_executesql N'update Table set Field=Field where RecID=@RecID',
N'Field bit,RecID int', Field = 0, RecID = 1
Everything looks fine, the variable 'Field' seems to be getting
defined, but the query doesn't execute!
Any suggestions would be appreciated. This is so simple, I must be
missing something!
Thanks!