【问题标题】:Winforms: How to upload a picture into SQL Server database using C#Winforms:如何使用 C# 将图片上传到 SQL Server 数据库
【发布时间】:2011-01-23 20:05:59
【问题描述】:

我想将图像上传到我的 SQL Server 数据库。我有两个按钮,一个图片框。使用浏览按钮,我可以从磁盘中选择文件,并将其显示在图片框中。

问题是我无法将图片从图片框保存到数据库中。

请帮我写代码。欣赏它。

【问题讨论】:

    标签: c# sql-server database winforms


    【解决方案1】:

    您可以直接从其路径保存图像(您已经拥有它)。

    试试这个:

        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();
    

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 2011-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多