C# byte ib = null 保存ib到sql的image属性字段
To save a byte array ib to an SQL image attribute field, you can use the following steps:
- Create a SQL connection and open it.
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
// Rest of the code goes here
}
- Create a SQL command to insert the byte array into the image field.
using (SqlCommand command = new SqlCommand("INSERT INTO YourTableName (ImageColumn) VALUES (@Image)", connection))
{
command.Parameters.Add("@Image", SqlDbType.Image).Value = ib;
// Execute the command
command.ExecuteNonQuery();
}
- Close the SQL connection.
connection.Close();
Make sure to replace YourTableName with the actual name of your table and ImageColumn with the name of the image attribute field in the table.
This code assumes you have a valid connectionString variable containing the connection string to your SQL database
原文地址: https://www.cveoy.top/t/topic/irTL 著作权归作者所有。请勿转载和采集!