c# 读取textbox1为 name的值picturebox1没有图片读取picturebox1的值为byte img 更新sop表的namenvarchar20、imgimage字段l
你可以使用下面的代码来读取textbox1的值为name,并将picturebox1中的图片保存为byte[] img:
string name = textbox1.Text;
byte[] img;
using (MemoryStream ms = new MemoryStream())
{
picturebox1.Image.Save(ms, picturebox1.Image.RawFormat);
img = ms.ToArray();
}
然后,你可以使用以下代码来更新sop表中的name和img字段:
string connectionString = "YourConnectionString";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
string query = "UPDATE sop SET name = @name, img = @img";
using (SqlCommand command = new SqlCommand(query, connection))
{
command.Parameters.AddWithValue("@name", name);
command.Parameters.AddWithValue("@img", img);
command.ExecuteNonQuery();
}
}
请确保将"YourConnectionString"替换为你的数据库连接字符串。此外,此代码假设你已经创建了一个名为"sop"的表,其中包含name和img字段
原文地址: https://www.cveoy.top/t/topic/irYw 著作权归作者所有。请勿转载和采集!