Error: Must Declare Variable

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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


    Boris Zakharin Guest

  2. Similar Questions and Discussions

    1. DECLARE SYNTAX
      declare @x int set @x = (SELECT max(ixBugEvent) FROM bugevent) UPDATE bugevent SET ixAttachment = (SELECT max(ixAttachment) FROM attachment),...
    2. "Must declare the variable '@…..'." in GridView/DatailsView with M
      I am testing ASP.NET 2.0 with MS SQL 2000. I get server error: "Exception Details: System.Data.SqlClient.SqlException: Must declare the variable...
    3. declare one variable
      hello. in my linux machine in the php.ini i have register_globals on i one page i have: <?php if($que){ echo($que); } ?>
    4. How to declare the result of a loop as a variable?
      I'm trying to include a list of people that's the result of looping through a recordset in a CDONTS mail. I'm trying to Dim the output of a loop,...
    5. how to declare session variable in global.asax file
      please provide code sample, i was having trouble declaring interger and string variable and can we also initialize them at the same time thanks...
  3. #2

    Default Re: 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.
    > [url]http://www.crtimmonsinc.com/[/url]

    Boris Zakharin Guest

  4. #3

    Default 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.


    Boris Zakharin Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139