sql exception was unhandled by user code

CL-IS
CL-IS used Ask the Experts™
on
Hello

Im using asp.net c# and i have I have a string which has a delete statement and the value of job is 'PME041011-K1'

string sqlDelete = "delete from wp4tbl_TblCompVerifySapBatch where Workorder = " + job;

but when it gets to the line - myCommand2.ExecuteNonQuery();

it says - sql exception was unhandled by user code
              Invalid column name 'PME041011'.
              Invalid column name 'K1'.

It looks like its splitting the value up?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
use the square brackets

change this:

string sqlDelete = "delete from wp4tbl_TblCompVerifySapBatch where Workorder = " + job;

to this:

string sqlDelete = "delete from wp4tbl_TblCompVerifySapBatch where Workorder = [" + job +"]";
Senior Systems and Integration Developer
Commented:
It's expecting Job to be a string, which means it needs to be wrapped in apostrophes:
string sqlDelete = "delete from wp4tbl_TblCompVerifySapBatch where Workorder = '" + job + "'"; 

Open in new window

Author

Commented:
OK i used your way and now i getting this just on one line

sql exception was unhandled by user code
              Invalid column name 'PME041011-K1'.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial