When i start my code with file upload control it's all over, but i have to fight with my exception
with exception message of
string or binary data would be truncated.I cannot come to know which binary data would be truncated
and also i had created a table of name INFORMATION with columns id,name,photo
query=
create table information (id int,name varchar(size),photo varbinary(max))
id=some number
name=name of the uploaded file
photo=content of uploaded file(eg:->JPEG OR PPG..ETC)
and also i had taken one
textbox to enter id no and one
fileuploadcontrol and one
button(upload)
here is my front end code
protected void btnupload_Click(object sender, EventArgs e)
{
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
string contenttype=FileUpload1.PostedFile.ContentType;
using (Stream fs=FileUpload1.PostedFile.InputStream)
{
using (BinaryReader br=new BinaryReader(fs))
{
byte[] bt = br.ReadBytes((int)fs.Length);
string constr = ConfigurationManager.ConnectionStrings["naveen"].ToString();
using (SqlConnection con=new SqlConnection(constr))
{
string query = "insert into information values(@id,@name,@photo)";
using (SqlCommand cmd=new SqlCommand(query))
{
cmd.Connection = con;
cmd.CommandText = query;
cmd.Parameters.AddWithValue("@id", TextBox1.Text);
cmd.Parameters.AddWithValue("@name", filename);
cmd.Parameters.AddWithValue("@photo", contenttype);
con.Open();
int i=cmd.ExecuteNonQuery();----->Here is the statement which i have got exception
con.Close();
if (i>0)
{
Label1.Text = "File uploaded succesfully";
}
else
{
Label1.Text = "failed to upload";
}
}
}
}
}
}
and how do i resolve this exception.... :)