How To Insert Images Into Sql Database

Posted by Aryan1982 under Silverlight on 2/2/2013 | Points: 10 | Views : 3653 | Status : [Member] | Replies : 5
My Question:-
How to Insert Images into SQL database in silverlight?

Regard Aryan
Thanks in Advance.




Responses

Posted by: Kamilacbe on: 2/2/2013 [Member] Starter | Points: 25

Up
0
Down
hi,

images can be inserted as binary data in SQL or on the other had you can store the location of the image in database and retrieve the image by reading the location from DB and pointing to that location .


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

Posted by: Aryan1982 on: 2/2/2013 [Member] Starter | Points: 25

Up
0
Down
Button_Click
{
datatable obj = new datatable();

obj.Name = txtname.Text;

//I have problem in this line
obj.Image = txtimage.text;// this line
}

if u have a full code for that please give me........
Thanks in advance
Aryan

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

Posted by: Kusumas on: 2/6/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Aryan,

ASP:
Select Image Here:
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnSubmit" runat="server" Text="Upload & Save" OnClick="SaveIamgeIntoDatabase" />

C# Code:
protected void SaveImageIntoDatabase(object sender, EventArgs e)
{
string fileName = FileUpload1.PostedFile.FileName;
int fileLength = FileUpload1.PostedFile.ContentLength;
byte[] imageBytes = new byte[fileLength];
FileUpload1.PostedFile.InputStream.Read(imageBytes, 0, fileLength);
SqlConnection conn = new SqlConnection(_connStr)
SqlCommand cmd = new SqlCommand("InsertImage", conn)
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter[] prms = new SqlParameter[2];
prms[0] = new SqlParameter("@fileName", SqlDbType.VarChar, 50);
prms[0].Value = fileName;
prms[1] = new SqlParameter("@fileContent", SqlDbType.Image);
prms[1].Value = imageBytes;
cmd.Parameters.AddRange(prms);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}


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

Posted by: Aryan1982 on: 2/6/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks for reply KUSUMAS but i am using silverlight with wcf service.
any code in silverlight plz give me.


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

Posted by: Kusumas on: 2/7/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Aryan,

Try this one i added zip code.
I don't have exact knowledge on silver light.

http://www.silverlightshow.net/items/Uploading-and-downloading-images-from-WCF-in-Silverlight.aspx
 Download source file

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

Login to post response