Error: Must Declare Variable

Discussion in 'ASP .Net' started by Boris Zakharin, Jul 21, 2003.

  1. 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
    Boris Zakharin, Jul 21, 2003
    #1
    1. Advertising

  2. 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 Zakharin, Jul 21, 2003
    #2
    1. Advertising

  3. 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.
    Boris Zakharin, Jul 22, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jiggaz
    Replies:
    6
    Views:
    32,106
    Raghudubba
    Nov 5, 2009
  2. =?Utf-8?B?S2VuIEFkZW5pamk=?=

    Must declare the scalar variable '@FirstName'

    =?Utf-8?B?S2VuIEFkZW5pamk=?=, Apr 26, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    80,005
    leojose
    Aug 17, 2007
  3. Oded Dror

    Must Declare the Scalar Variable error

    Oded Dror, May 28, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    18,980
    Oded Dror
    May 28, 2006
  4. Replies:
    0
    Views:
    2,383
  5. Mark
    Replies:
    1
    Views:
    1,504
Loading...

Share This Page