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. Web Development
  3. ASP.NET
  4. Question about saving an image to SQL database

Question about saving an image to SQL database

Scheduled Pinned Locked Moved ASP.NET
databasehelpquestiontutorial
3 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.
  • A Offline
    A Offline
    Aptiva Dave
    wrote on last edited by
    #1

    Okay, here is my problem: I've got a web site that allows users to edit their profile. Part of this profile information will be used to populate a contact page which will include a picture of the user. Now, I'm able to upload the pictures just fine into a sql 2005 database and display that image, but if the user doesn't add an image (which they are allow not to do) then I get stuck on how to populate that into my sql stored procedure's parameter list. I keep getting an error every time I try saving the profile without an image in the file upload box. Here is the code that I am using to try to put in a dbnull value:

    cmd.Parameters.AddWithValue("@picture", SqlDbType.Image).Value = DBNull.Value

    Any ideas on what I'm doing wrong?

    N 1 Reply Last reply
    0
    • A Aptiva Dave

      Okay, here is my problem: I've got a web site that allows users to edit their profile. Part of this profile information will be used to populate a contact page which will include a picture of the user. Now, I'm able to upload the pictures just fine into a sql 2005 database and display that image, but if the user doesn't add an image (which they are allow not to do) then I get stuck on how to populate that into my sql stored procedure's parameter list. I keep getting an error every time I try saving the profile without an image in the file upload box. Here is the code that I am using to try to put in a dbnull value:

      cmd.Parameters.AddWithValue("@picture", SqlDbType.Image).Value = DBNull.Value

      Any ideas on what I'm doing wrong?

      N Offline
      N Offline
      NeverHeardOfMe
      wrote on last edited by
      #2

      That doesn't look right to me. Can't you just put

      cmd.Parameters.AddWithValue("@picture", DBNull.Value)

      ? (Assuming your "picture" field allows nulls, of course...)

      I 1 Reply Last reply
      0
      • N NeverHeardOfMe

        That doesn't look right to me. Can't you just put

        cmd.Parameters.AddWithValue("@picture", DBNull.Value)

        ? (Assuming your "picture" field allows nulls, of course...)

        I Offline
        I Offline
        InderK
        wrote on last edited by
        #3

        I guess make image field mandatory or call this method only if there is value in @picture. Thanks, RK..

        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