Error: Must Declare Variable  
Author Message
GMorrison





PostPosted: Mon Jul 21 16:40:51 CDT 2003 Top

ASP.Net >> Error: Must Declare Variable 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

Web Programming190  
 
 
Boris





PostPosted: Mon Jul 21 16:40:51 CDT 2003 Top

ASP.Net >> Error: Must Declare Variable Yes, I tried hard-coding the value to zero, but the error is still reported.

> Boris,
>
> Are you sure Request["item"] is not null?
>
>
> Chris.
> -------------
> C.R. Timmons Consulting, Inc.
> http://www.crtimmonsinc.com/


 
 
Boris





PostPosted: Mon Jul 21 20:04:58 CDT 2003 Top

ASP.Net >> Error: Must Declare Variable 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.