I am trying to insert images into a sql server database? I make the data type as image already but i dont know how to insert the image into the database? Any help will be great
I am trying to insert images into a sql server database? I make the data type as image already but i dont know how to insert the image into the database? Any help will be great
// Source Code for Save the image file into the database
public void OnUpload(Object sender, EventArgs e)
{
// Create a byte[] from the input file
int len = Upload.PostedFile.ContentLength;
byte[] pic = new byte[len];
Upload.PostedFile.InputStream.Read (pic, 0, len);
// Insert the image and comment into the database
SqlConnection connection = new
SqlConnection (@"server=INDIA\INDIA;database=iSense;uid=sa;pwd=i ndia");
try
{
connection.Open ();
SqlCommand cmd = new SqlCommand ("insert into Image "
+ "(Picture, Comment) values (@pic, @text)", connection);
cmd.Parameters.Add ("@pic", pic);
cmd.Parameters.Add ("@text", Comment.Text);
cmd.ExecuteNonQuery ();
}
finally
{
connection.Close ();
}
}
try this code
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks