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

前端 未结 2 504
予麋鹿
予麋鹿 2021-01-06 09:14

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

相关标签:
2条回答
  • 2021-01-06 09:51

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

    Haven't tried the code myself.

    0 讨论(0)
  • 2021-01-06 09:52

    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();
    
    0 讨论(0)
提交回复
热议问题