Click here to Skip to main content
15,908,445 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I Had store image into database.

C#
FileUpload img = (FileUpload)image;
Byte[] imgByte = null;
if (img.HasFile && img.PostedFile != null)
{
    HttpPostedFile File = image.PostedFile;
    imgByte = new Byte[File.ContentLength];
    File.InputStream.Read(imgByte, 0, File.ContentLength);
}

SqlConnection con = new SqlConnection("uid=sa;pwd=123;database=project");
con.Open();
SqlCommand cmd = new SqlCommand("insert into student values('"+regno+"',"+imgByte+")", con);


how can i take imgByte varible in sqlcommand
please solve that error
Posted
Updated 16-May-11 11:18am
v3

Byte[] imgByte;
SqlCommand cmd = new SqlCommand("insert into student values('"+regno+"',"+imgByte+")", con);


Is it correct statement or not?
 
Share this answer
 
v2
try this

SqlCommand cmd = new SqlCommand("insert into student values(@RegNo,@imgByte)", con);
cmd.Parameters.AddWithValue("@RegNo",regno);
cmd.Parameters.AddWithValue("@imgByte",imgByte);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900