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. INSERT IMAGES TO SQL SERVER TABLE USING C# CODING

INSERT IMAGES TO SQL SERVER TABLE USING C# CODING

Scheduled Pinned Locked Moved ASP.NET
questioncsharpdatabasesql-serversysadmin
8 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.
  • P Offline
    P Offline
    Phivos Stylianides
    wrote on last edited by
    #1

    Hi, i'm trying to save preset images of type jpeg in a SQL table. My code below will be executed within a method every time i add a picture in the table. The table is called ITEM and the column with the type image is called item_picture. And the application root is ~/images/ where i have stored all the images. try { byte[] image = new byte[4]; string qry = "insert into ITEM(item_picture) values(@OriginalPath)"; command = new SqlCommand(qry,connection); command.Parameters.Add(new SqlParameter("@OriginalPath","~/images/app1.jpg")); } finally { connection.Open(); command.ExecuteNonQuery(); connection.Close(); } I get the following error: Operand type clash: nvarchar is incompatible with image How can i get this right? Thanks!

    P 1 Reply Last reply
    0
    • P Phivos Stylianides

      Hi, i'm trying to save preset images of type jpeg in a SQL table. My code below will be executed within a method every time i add a picture in the table. The table is called ITEM and the column with the type image is called item_picture. And the application root is ~/images/ where i have stored all the images. try { byte[] image = new byte[4]; string qry = "insert into ITEM(item_picture) values(@OriginalPath)"; command = new SqlCommand(qry,connection); command.Parameters.Add(new SqlParameter("@OriginalPath","~/images/app1.jpg")); } finally { connection.Open(); command.ExecuteNonQuery(); connection.Close(); } I get the following error: Operand type clash: nvarchar is incompatible with image How can i get this right? Thanks!

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      Your SQL parameter should be of type SqlDbType.Image

      Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

      P 1 Reply Last reply
      0
      • P pmarfleet

        Your SQL parameter should be of type SqlDbType.Image

        Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

        P Offline
        P Offline
        Phivos Stylianides
        wrote on last edited by
        #3

        yes but, where should i include the path of the image?

        N 1 Reply Last reply
        0
        • P Phivos Stylianides

          yes but, where should i include the path of the image?

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          If you're uploading the image to the database, why do you need the path? :doh:


          only two letters away from being an asset

          P 1 Reply Last reply
          0
          • N Not Active

            If you're uploading the image to the database, why do you need the path? :doh:


            only two letters away from being an asset

            P Offline
            P Offline
            Phivos Stylianides
            wrote on last edited by
            #5

            i need the images contained in a relative folder to be all uploaded in the database to be used later in my application. I will not use an upload tool to be used manually from the user so there has to be a path!

            N 1 Reply Last reply
            0
            • P Phivos Stylianides

              i need the images contained in a relative folder to be all uploaded in the database to be used later in my application. I will not use an upload tool to be used manually from the user so there has to be a path!

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #6

              Ok, so you didn't understand. If the images are in your database and your application will use those images, you don't need a path. The path is irrelevant, the image is stored in the database. If, however, you need to the image to be at the path, then you don't need to store the image in the database, only the path.


              only two letters away from being an asset

              P 1 Reply Last reply
              0
              • N Not Active

                Ok, so you didn't understand. If the images are in your database and your application will use those images, you don't need a path. The path is irrelevant, the image is stored in the database. If, however, you need to the image to be at the path, then you don't need to store the image in the database, only the path.


                only two letters away from being an asset

                P Offline
                P Offline
                Phivos Stylianides
                wrote on last edited by
                #7

                The images are not in the database yet. They are stored in the path mentioned, so far, and i'm trying to figure out a way to store them in the database. The code i posted in my first post does not work and i couldn't debug it. I'm looking for the appropriate corrections to make on my code so that my application will store the images in the database or write new code from scratch if there is a better way to do this. Thanks!

                N 1 Reply Last reply
                0
                • P Phivos Stylianides

                  The images are not in the database yet. They are stored in the path mentioned, so far, and i'm trying to figure out a way to store them in the database. The code i posted in my first post does not work and i couldn't debug it. I'm looking for the appropriate corrections to make on my code so that my application will store the images in the database or write new code from scratch if there is a better way to do this. Thanks!

                  N Offline
                  N Offline
                  Not Active
                  wrote on last edited by
                  #8

                  If you want to store images in a SQL Server database then look here. http://www.codeproject.com/KB/database/albumviewer.aspx[^] What the hell is all the talk about storing the path to the image? :confused:


                  only two letters away from being an asset

                  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