Error: Must Declare Variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Boris Zakharin

    #1

    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=SQLO LEDB.1;Integrat ed Security=SSPI;P ersist
    Security Info=False;Init ial Catalog=ACRPPhi lly;Data
    Source=COMPUSA\ \VSdotNET;Use Procedure for Prepare=1;Auto
    Translate=True; Packet Size=4096;Works tation ID=COMPUSA;Use Encryption for
    Data=False;Tag with column collation when possible=False" );

    OleDbDataAdapte r datDetail = new OleDbDataAdapte r();

    OleDbCommand cmdDetail = new OleDbCommand("S ELECT 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.Selec tCommand = cmdDetail;

    cmdDetail.Param eters.Add("@job _id", OleDbType.Integ er, 10).Value =
    Request["item"];

    DataSet dsDetail = new DataSet();

    datDetail.Fill( dsDetail);

    -- End Code --

    What am I doing wrong here?

    Thanks,
    Boris Zakharin


  • Boris Zakharin

    #2
    Re: Error: Must Declare Variable

    Yes, I tried hard-coding the value to zero, but the error is still reported.
    [color=blue]
    > Boris,
    >
    > Are you sure Request["item"] is not null?
    >
    >
    > Chris.
    > -------------
    > C.R. Timmons Consulting, Inc.
    > http://www.crtimmonsinc.com/[/color]


    Comment

    • Boris Zakharin

      #3
      Re: 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.


      Comment

      Working...