use*_*546 4 c# database sql-server winforms
我想将图像上传到我的SQL Server数据库.我有两个按钮,一个图片框.使用浏览按钮,我可以从磁盘中选择文件,并将其显示在图片框中.
问题是我无法将图片从picturebox保存到数据库中.
请帮我解决问题.欣赏它.
您可以直接从其路径保存图像(您已经拥有它).
试试这个:
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();
Run Code Online (Sandbox Code Playgroud)