0

I have a table like this.

 myID   Name     Pic
   1     Shan    
   2     Sharon 

myId column is integer type, Name is varchar(10) and pic is type of image data type. I'm using SQL Server.

In a normal insert procedure, in which if you don't have a column name of data type "image" I know the insert would look like this.

      INSERT INTO myTable
      VALUES (1,Shan);

How to insert image data type column how to select the file. How to write an insert query to a table which is having a image data type column?

Thanks in advance.

6
  • @bummi column type is not binary or blob, it's image data type. Commented Oct 14, 2014 at 9:39
  • They are all stored binary ntext, text, and image if (Select CAST(PICAsImage as Varbinary(max)) from PICS where ID=1) = (Select PICAsVarBinary from PICS where ID=2) print 'true' will print true if the same image was loaded via OPENROWSET(BULK Commented Oct 14, 2014 at 9:53
  • @bummi I didn't want a casted answer, I just asked a simple query, with a simple explanation if could. i don't understand what you are talking about. i just wanted to know how to set file path for the image. Commented Oct 14, 2014 at 10:00
  • It's shown in the answer to then question linked above stackoverflow.com/a/4711255 image is a deprecated fieldkind, the behavior is identic to Varbinary (max) Commented Oct 14, 2014 at 10:05
  • @bummi I went through that answer, why is that SELECT statement there, can you point a detailed explanation, or a tutorial which is explaining. Commented Oct 14, 2014 at 10:14

1 Answer 1

4

1.Create FileStream with your image file.

2.Create byte array of length FileStream.Length.

3.use this byte array as value for your Pic column.

Here is good article on code project - http://www.codeproject.com/Articles/354639/Storing-and-Retrieving-Images-from-SQL-Server-Us

Another solution which I can think of is, you just store the absolute disk path of your image file. You just add column of nvarchar type and use this for path.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks the tutorial gave me just basic idea on how to create my concept in code. Many Thanks again.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.