Click here to Skip to main content
15,921,226 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All


I am getting this error message when i try to store the binary data to varbinary(max) column type in sql server database. My requirement is to store the image as varbinary(max) in sql server and to display in the interface too.

Can anyone suggest me a good sample and to resolve this error.



Regards
Froxy
Posted
Comments
Prerak Patel 13-Jul-11 6:07am    
Will you show how you are saving? Share some code.
sathiyak 16-Feb-12 5:55am    
if (uploadresume.HasFile == true)
{
if ((uploadresume.PostedFile.ContentLength / 1024) <= 300)
{
cn.Open();
Stream fs = uploadresume.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "pupusrresume";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@loginemailid", Convert.ToInt32(Session["loginemailid"].ToString()));
//cmd.Parameters.AddWithValue("@resume", usrresume);
cmd.Parameters.Add("@resume", SqlDbType.VarBinary).Value = bytes;
cmd.Connection = cn;
cmd.ExecuteNonQuery();
cn.Close();
//clear();
Page.ClientScript.RegisterStartupScript(this.GetType(), "Updated", "<script>alert('Yor resume Updated')</script>");
}
}

1 solution

Without seeing your code, I would guess that you are trying to provide a string or other character stream, probably in the form of
sqlstring = "INSERT INTO myTable (binaryField) VALUES ('" + myArrayOfBytes + "')"
Instead, use a parametrized query and provide the bytes as a parameter.
 
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