Error: Must Declare Variable

  • Thread starter Thread starter Boris Zakharin
  • Start date Start date
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
 
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.
 
Back
Top