Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void submitbtn_Click(object sender, EventArgs e)
    {
        byte[] image = null;
        if (FileUpload1.HasFile)
        {
            int length = FileUpload1.PostedFile.ContentLength;
            image = new byte[length];
            HttpPostedFile img = FileUpload1.PostedFile;
            img.InputStream.Read(image, 0, length);
        }
            string query = "Insert into pro(product,prname,prdes,key,price,image) values ('"+selec+"','"+prnametxt.Text+"','"+prdestxt.Text+"','"+keytxt.Text+"','"+pricetxt.Text+"',@imgs)";
            MySqlCommand cmd = new MySqlCommand(query, con);
            cmd.Parameters.AddWithValue("@imgs", image);
            cmd.ExecuteNonQuery();
        
    }


While Insering I am getting this error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key,price,image)values('','Admin','Admin','Admin','44','System.Byte[]')' at line 1
Posted
Comments
ZurdoDev 11-Mar-14 7:27am    
Since you need to insert the bytes you'll probably have to declare the type, something like
cmd.Parameters.Add("@imgs", SqlDbType.VarBinary, getthelength).Value = image;
Gokul Athithan 11-Mar-14 7:38am    
I have done like this also cmd.Parameters.Add("@imgs",MySqlDbType.LongBlob).Value=image;
But also same error.
ZurdoDev 11-Mar-14 7:56am    
I have not used MySql but I would suggest searching how to use C#, mysql, to insert byte array.
Gokul Athithan 11-Mar-14 8:54am    
Sir,I got the answer where "Key" is an reserved keyword in the MySql so it did't insert
ZurdoDev 11-Mar-14 8:57am    
Interesting. Thanks for updating.

1 solution

"Key" is an reserved keyword in the MySql so it did't get insert
 
Share this answer
 
Comments
Ankur\m/ 11-Mar-14 9:15am    
Passing it in rectangular brackets [] should work.

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