how to insert and retrieve images from sql databasee...

U

Umar

hi

i am trying to store images in sql database in binary form .. i do it
..... but when i want to show that stored images on my web form any
where i got only first 16 bytes of the image. so i got error and cant
display the image. but can store it successfully.

plz help me and guide me its urgent



thanx
 
D

dllhell

Umar said:
hi

i am trying to store images in sql database in binary form .. i do it
.... but when i want to show that stored images on my web form any
where i got only first 16 bytes of the image. so i got error and cant
display the image. but can store it successfully.

plz help me and guide me its urgent



thanx

DataSet DST = new DataSet("MyPic");
byte[] Arr = new byte[0];
DataRow DRow;
SqlDataAdapter SDA = new SqlDataAdapter(SQLappend, Conn);
SqlCommandBuilder CBuild = new SqlCommandBuilder(SDA);
SDA.Fill(DST, "MyPic");

try
{
DRow = DST.Tables["MyPic"].Rows[0];

Arr = (byte[])DRow["ColumnWithPic"];
int ArraySize = new int();
ArraySize = Arr.GetUpperBound(0);
FileStream FStream = new FileStream(@"c:\MyPic.bmp",
FileMode.OpenOrCreate, FileAccess.Write);
FStream.Write(Arr, 0, ArraySize);
FStream.Close();FStream.Dispose();DRow.Delete();
}
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Umar said:
hi

i am trying to store images in sql database in binary form .. i do it
.... but when i want to show that stored images on my web form any
where i got only first 16 bytes of the image. so i got error and cant
display the image. but can store it successfully.

How are you extracting the image from the DB?
I assume you are creating files for these extracted images right?


The way I do it is :
1- Check if the image is not already extracted, if so just return the path
2- Extract the image
3- Save it to disk to a dir for this purpose
4- return the link to the image file


Simple to implement,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top