下面是一个示例代码,演示如何清空PictureBox控件中的图片,并更新SOP表的name、cat和img字段。

string connectionString = "Your_Connection_String"; // 替换为你的连接字符串

// 清空PictureBox控件中的图片
pictureBox1.Image = null;

// 更新SOP表的name、cat和img字段
string name = "LL";
string cat = "A";

using (SqlConnection connection = new SqlConnection(connectionString))
{
    connection.Open();

    // 更新name和cat字段
    string updateQuery = "UPDATE SOP SET name = @name, cat = @cat WHERE id = 1"; // 替换id为你需要更新记录的id
    using (SqlCommand command = new SqlCommand(updateQuery, connection))
    {
        command.Parameters.AddWithValue("@name", name);
        command.Parameters.AddWithValue("@cat", cat);
        command.ExecuteNonQuery();
    }

    // 设置img字段为null
    string updateImgQuery = "UPDATE SOP SET img = NULL WHERE id = 1"; // 替换id为你需要更新记录的id
    using (SqlCommand command = new SqlCommand(updateImgQuery, connection))
    {
        command.ExecuteNonQuery();
    }
}

请注意,上述代码假设SOP表中的id字段用于唯一标识每个记录。确保将连接字符串替换为你自己的连接字符串,并将id值替换为你需要更新记录的实际id值

c# picturebox1清空图片byte image的值为空 更新sop表的namenvarchar20、catnvarchar10、imgimage字段其中name=LL、cat=A、img=null

原文地址: https://www.cveoy.top/t/topic/irYk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录