INSERT IMAGES TO SQL SERVER TABLE USING C# CODING
-
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!
-
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!
-
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
yes but, where should i include the path of the image?
-
yes but, where should i include the path of the image?
If you're uploading the image to the database, why do you need the path? :doh:
only two letters away from being an asset
-
If you're uploading the image to the database, why do you need the path? :doh:
only two letters away from being an asset
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!
-
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!
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
-
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
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!
-
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!
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