|
when i m trying to update image in sql database i m getting error as"Cannot bulk load. The file "System.Byte[]" does not exist."
my code is as follows.pls help.
protected void Button1_Click(object sender, EventArgs e)
{
{
if (FileUpload1.HasFile)
{
byte[] productImage = FileUpload1.FileBytes;
string constr = "Server=AOD257; Database=Edusocial;User ID=sa; Password=password";
string query = "UPDATE Profile SET [Pic] = (SELECT Pic.* from Openrowset(Bulk '" + productImage + "', Single_Blob) MyImage) where Id =11651658";
SqlConnection con = new SqlConnection(constr);
SqlCommand com = new SqlCommand(query, con);
com.Parameters.Add("@Pic", SqlDbType.Image).Value = productImage;
con.Open();
int result = com.ExecuteNonQuery();
con.Close();
if (result > 0)
{
Response.Redirect("Default.aspx");
}
}
else
{
lblmessage.Text = "Please Select Image File";
lblmessage.Visible = true;
}
}
}
|
|
|
|
|
I can't see how that would work, mixing unicode with bytes to enter into a blob.
"UPDATE Profile SET [Pic] = (SELECT Pic.* from Openrowset(Bulk '" + productImage + "', Single_Blob) MyImage) where Id =11651658";
versus
"UPDATE Profile SET [Pic] = productImage WHERE Id =11651658";
in which the latter is pure bytes from the file upload.
|
|
|
|
|
"UPDATE Profile SET [Pic] = '"+productImage+"' WHERE Id =11651658"
this query is working fine.but then image in image box is broked.its not been displayed.pls help.
|
|
|
|
|
You're nearly there:
"UPDATE Profile SET [Pic] = @Pic WHERE Id = 11651658"
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|