开发者

Winforms: How to upload a picture into SQL Server database using C#

开发者 https://www.devze.com 2022-12-21 19:36 出处:网络
I want to upload images to my SQL Server database. I have two buttons , One picture box. With the browse button, I am able to select the file from disk, and it is displayed into the picturebox.

I want to upload images to my SQL Server database. I have two buttons , One picture box. With the browse button, I am able to select the file from disk, and it is displayed into the picturebox.

The problem is that I am not able to save the picture from picturebox 开发者_运维百科into the database.

Please help me out with the code. Appreciate it.


You can save the image directly from its path (you have it already).

Try this:

    byte[] img = File.ReadAllBytes("your image path");

    mySqlCommand = "INSERT INTO MyTable(Image) VALUES(@Image)";//mySqlCommand is a SqlCommand, and @Image is a parameter 
    mySqlCommand.Parameters.AddWithValue("@Image", img);
    mySqlCommand.ExecuteNonQuery();


Sending/Receiving PictureBox Image in C# To/From Microsoft SQL SERVER

Haven't tried the code myself.

0

精彩评论

暂无评论...
验证码 换一张
取 消