简体   繁体   中英

I want to save an image from my C# form application to SQL Server Database

I want to save an image from my C# form application to SQL Server Database, currently im doing this: In class library class named PhotoCL:

public void AddPhoto(int id, Image  photo)
    {
        db.ExecuteNonQuery("spAddPhoto", new object[] { id, photo});
    }

"spAddPhoto" is the stored Procedure which have 2 parameters, @id int , @img image In database the table of photos also have two columns with same data types as mentioned above in SP.

This is the Code behind my AddPhoto Button:

private void button1_Click(object sender, EventArgs e)
    {
        mp.AddPhoto(Convert.ToInt32(comboBox1.SelectedValue),pictureBox1.Image);
    }

I m getting this error at runtime(Debugging):

"Failed to convert parameter value from a Bitmap to a Byte[]."

Please help me out.. Thanks in advance..

You don't insert an image like this to a database, you should insert a flow of byte corresponding to the image.

Would this article be of help ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM