To save a byte array ib to an SQL image attribute field, you can use the following steps:

  1. Create a SQL connection and open it.
using (SqlConnection connection = new SqlConnection(connectionString))
{
    connection.Open();
    
    // Rest of the code goes here
}
  1. 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();
}
  1. 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

C# byte ib = null 保存ib到sql的image属性字段

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

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