Error: Must Declare Variable

B

Boris Zakharin

I have the following code upon which I receive the error "Must declare the
variable '@job_id'".

--Begin Code --

OleDbConnection conDetail = new
OleDbConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
Security Info=False;Initial Catalog=ACRPPhilly;Data
Source=COMPUSA\\VSdotNET;Use Procedure for Prepare=1;Auto
Translate=True;Packet Size=4096;Workstation ID=COMPUSA;Use Encryption for
Data=False;Tag with column collation when possible=False");

OleDbDataAdapter datDetail = new OleDbDataAdapter();

OleDbCommand cmdDetail = new OleDbCommand("SELECT job_id, [Company Name],
[Position Title], [Position Contact Information], [Position Description],
discipline_id, City, state_id FROM dbo.jobs WHERE (job_id = @job_id)",
conDetail);

datDetail.SelectCommand = cmdDetail;

cmdDetail.Parameters.Add("@job_id", OleDbType.Integer, 10).Value =
Request["item"];

DataSet dsDetail = new DataSet();

datDetail.Fill(dsDetail);

-- End Code --

What am I doing wrong here?

Thanks,
Boris Zakharin
 
B

Boris Zakharin

Yes, I tried hard-coding the value to zero, but the error is still reported.
 
B

Boris Zakharin

I got it to work by change to WHERE (job_id = ?). This is acceptable for my
interests, but I should be able to create named parameters, right? I'm using
MSDE to host the database.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top