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. General Programming
  3. C / C++ / MFC
  4. passing values of parameter in code itself, must declare scalar var. .error

passing values of parameter in code itself, must declare scalar var. .error

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelp
4 Posts 3 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.
  • S Offline
    S Offline
    suni_dotnet
    wrote on last edited by
    #1

    Hi, if a condition is met, my code inserts image into a column of database table. I used below code, passing the value of picture in code, this is giving me "Must declare the scalar variable "@picbyte", i declared its value(code below).any idea why iam getting this error... string filepath = "C:\\Users\\Prakash\\Pictures\\pic.jpg"; FileStream imgfile = new FileStream(filepath, FileMode.Open,FileAccess.Read, FileShare.Read); byte[] picbyte = new byte[Convert.ToInt32(imgfile.Length)]; imgfile.Read(picbyte, 0, System.Convert.ToInt32(imgfile.Length)); SqlCommand cmd3 = new SqlCommand("Insert into " +Label7.Text+"(Picture)"+ " values(@picbyte)",con); cmd3.Parameters.Add("@Picture",System.Data.SqlDbType.Image); cmd3.Parameters["@Picture"].Value=picbyte; cmd3.ExecuteNonQuery(); thanks in advance

    modified on Tuesday, January 13, 2009 4:49 PM

    H 1 Reply Last reply
    0
    • S suni_dotnet

      Hi, if a condition is met, my code inserts image into a column of database table. I used below code, passing the value of picture in code, this is giving me "Must declare the scalar variable "@picbyte", i declared its value(code below).any idea why iam getting this error... string filepath = "C:\\Users\\Prakash\\Pictures\\pic.jpg"; FileStream imgfile = new FileStream(filepath, FileMode.Open,FileAccess.Read, FileShare.Read); byte[] picbyte = new byte[Convert.ToInt32(imgfile.Length)]; imgfile.Read(picbyte, 0, System.Convert.ToInt32(imgfile.Length)); SqlCommand cmd3 = new SqlCommand("Insert into " +Label7.Text+"(Picture)"+ " values(@picbyte)",con); cmd3.Parameters.Add("@Picture",System.Data.SqlDbType.Image); cmd3.Parameters["@Picture"].Value=picbyte; cmd3.ExecuteNonQuery(); thanks in advance

      modified on Tuesday, January 13, 2009 4:49 PM

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      First do you know I cant see errors on your monitor and second it seems you use of Managed C++/CLI so you need to ask on the Managed C++/CLI[^]. ;)

      Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

      S 1 Reply Last reply
      0
      • H Hamid Taebi

        First do you know I cant see errors on your monitor and second it seems you use of Managed C++/CLI so you need to ask on the Managed C++/CLI[^]. ;)

        Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

        S Offline
        S Offline
        suni_dotnet
        wrote on last edited by
        #3

        Hi, iam getting "Must declare the scalar variable "@picbyte" error.... and i supplied the value in my code.. cmd3.Parameters["@Picture"].Value=picbyte; this is a sql code used to insert an image into database for a specific condition, which i'll retrieve in gridview.. i neednot pass the value dynamically so iam passing the value in code itself.. why iam getting this error even though i passed the value... thanks

        L 1 Reply Last reply
        0
        • S suni_dotnet

          Hi, iam getting "Must declare the scalar variable "@picbyte" error.... and i supplied the value in my code.. cmd3.Parameters["@Picture"].Value=picbyte; this is a sql code used to insert an image into database for a specific condition, which i'll retrieve in gridview.. i neednot pass the value dynamically so iam passing the value in code itself.. why iam getting this error even though i passed the value... thanks

          L Offline
          L Offline
          leckey 0
          wrote on last edited by
          #4

          Did you even READ Hamid's response? YOU ARE ON THE WRONG FORUM.

          "Well, we're getting "F"'d at work. WPF, WCF, and WWF... WTF?" --John Simmons

          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