How to upload image in sql database.

Posted by Sathiya_Narayanan under ASP.NET on 7/5/2012 | Points: 10 | Views : 3850 | Status : [Member] | Replies : 4
Hi
I am doing an application in that image is required for that how to upload image into database.
and that database table to be displayed in the database.
How to do this task if anybody know please share it.







Thanks

SATHIYANARAYANAN


Responses

Posted by: Rajkatie on: 7/5/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Kindly refer following link
http://www.aspdotnetcodes.com/Insert_Images_Database.aspx

Rajesh Patel
.Net Trainer(MSCD | MCT | MS)
Brainbench (Asp.Net 4.5 and C# 5.0)

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vforvijay on: 7/5/2012 [Member] Starter | Points: 25

Up
0
Down
Hi..Refer the below to upload image in sql database

http://www.dotnetcode.in/2011/02/upload-image-or-file-into-database-in.html
http://www.dotnetcode.in/2011/06/how-to-retrieve-uploaded-images-from.html

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Johnbhatt on: 7/5/2012 [Member] Starter | Points: 25

Up
0
Down
Here is a code for inserting Image in to Database Column of Type Image.

    protected void Button1_Click(object sender, EventArgs e)

{
SqlCommand comm = new SqlCommand();
byte[] bt;
try
{
comm.CommandText = "sp_tblusers";
comm.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
comm.CommandType = CommandType.StoredProcedure;
int imagelength = FileUpload1.PostedFile.ContentLength;
bt = new byte[FileUpload1.PostedFile.ContentLength];
FileUpload1.PostedFile.InputStream.Read(bt, 0, imagelength);
comm.Parameters.AddWithValue("@profilePic", bt);
comm.Connection.Open();
if (comm.Connection.State == ConnectionState.Open)
{
if (comm.ExecuteNonQuery() > 0)
Response.Write("Image Uploaded");
}
}
catch (Exception ex)
{
throw;
}
}


Note: sp_tblusers is Stored Procedure and will not work directly in your system. So change code here.

Get this and modify according to your need.

John Bhatt
Glad to Know, Free to Share.....
http://www.johnbhatt.com

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 7/6/2012 [Member] Starter | Points: 25

Login to post response