Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Error while uploading using OleDb

Error while uploading using OleDb

Scheduled Pinned Locked Moved Database
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jithbiz0033
    wrote on last edited by
    #1

    Hi, I am working with a program for uploading and downloading files.I am able to upload and download files with SqlConnection.But when I use OleDbConnection it shows following error while uploading the files OleDbException : "Must declare the variable '@id'." Error Code : -2147217900 {"Must declare the variable '@id'."} I am using the parameters to the insert the values.for all the parameters it shows the same kind of error. Please give your valuable Suggestions or codings Thanks Jith

    C 1 Reply Last reply
    0
    • J jithbiz0033

      Hi, I am working with a program for uploading and downloading files.I am able to upload and download files with SqlConnection.But when I use OleDbConnection it shows following error while uploading the files OleDbException : "Must declare the variable '@id'." Error Code : -2147217900 {"Must declare the variable '@id'."} I am using the parameters to the insert the values.for all the parameters it shows the same kind of error. Please give your valuable Suggestions or codings Thanks Jith

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      jithbiz0033 wrote:

      Please give your valuable Suggestions or codings

      Without seeing your code, it is difficult to suggest a corrective solution.


      Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website

      J 1 Reply Last reply
      0
      • C Colin Angus Mackay

        jithbiz0033 wrote:

        Please give your valuable Suggestions or codings

        Without seeing your code, it is difficult to suggest a corrective solution.


        Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website

        J Offline
        J Offline
        jithbiz0033
        wrote on last edited by
        #3

        Hi, The following coding threw the error. OleDbConnection mycon = new OleDbConnection(con); OleDbCommand mycom = new OleDbCommand("insert into files (Id,FileData) values (@id,@filedata)", mycon); OleDbParameter param0= new OleDbParameter("@id",OleDbType.Guid); param0.value=id; //initially got guid in id; mycom.Parameters.Add(param0); OleDbParameter param0= new OleDbParameter("@filedata",OleDbType.VarBinary); param1.value=filedata; //initially got byte[] in filedata mycom.Parameters.Add(param1); mycon.Open(); mycom.ExecuteNonQuery(); mycon.Close(); Now I changed my coding as below. OleDbConnection mycon = new OleDbConnection(con); OleDbCommand mycom = new OleDbCommand("insert into files (Id,FileData) values (?,?)", mycon); mycom.Parameters.Add("@id", OleDbType.Guid).Value = id; mycom.Parameters.Add("@filedata", OleDbType.VarBinary, fileData.Length).Value = fileData; mycon.Open(); mycom.ExecuteNonQuery(); mycon.Close(); It is working fine.But I want to know why the first coding threw the error Thanks Jith

        C 1 Reply Last reply
        0
        • J jithbiz0033

          Hi, The following coding threw the error. OleDbConnection mycon = new OleDbConnection(con); OleDbCommand mycom = new OleDbCommand("insert into files (Id,FileData) values (@id,@filedata)", mycon); OleDbParameter param0= new OleDbParameter("@id",OleDbType.Guid); param0.value=id; //initially got guid in id; mycom.Parameters.Add(param0); OleDbParameter param0= new OleDbParameter("@filedata",OleDbType.VarBinary); param1.value=filedata; //initially got byte[] in filedata mycom.Parameters.Add(param1); mycon.Open(); mycom.ExecuteNonQuery(); mycon.Close(); Now I changed my coding as below. OleDbConnection mycon = new OleDbConnection(con); OleDbCommand mycom = new OleDbCommand("insert into files (Id,FileData) values (?,?)", mycon); mycom.Parameters.Add("@id", OleDbType.Guid).Value = id; mycom.Parameters.Add("@filedata", OleDbType.VarBinary, fileData.Length).Value = fileData; mycon.Open(); mycom.ExecuteNonQuery(); mycon.Close(); It is working fine.But I want to know why the first coding threw the error Thanks Jith

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          It may be possible that your back end database doesn't understand named parameters and uses the parameter's position instead. Also, it will prefer the ? notation for positioning parameters rather than the @ notation.


          Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website

          J 1 Reply Last reply
          0
          • C Colin Angus Mackay

            It may be possible that your back end database doesn't understand named parameters and uses the parameter's position instead. Also, it will prefer the ? notation for positioning parameters rather than the @ notation.


            Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website

            J Offline
            J Offline
            jithbiz0033
            wrote on last edited by
            #5

            Hi, Thanks for the explanation.I didn't really knew that the SQL servers prefers different parameters. Thanks :cool: Jith -- modified at 0:50 Thursday 22nd March, 2007

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups