111,094
社区成员




FileStream fs = new FileStream("E:\\a.png", FileMode.Open);
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, (int)fs.Length);
fs.Close();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Server=****;Database=****;User ID=****;Pwd=****";
conn.Open();
SqlCommand com = new SqlCommand();
com.Connection = conn;
com.CommandText = "insert into photo_t values(@photo)";
SqlParameter param = new SqlParameter();
param.ParameterName = "photo";
param.SqlDbType = SqlDbType.Image;
param.Value = bytes;
com.Parameters.Add(param);
com.ExecuteNonQuery();
conn.Close();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Server=****;Database=****;User ID=****;Pwd=****";
conn.Open();
SqlCommand com = new SqlCommand();
com.Connection = conn;
com.CommandText = "select photo from photo_t where id=1";
object obj = com.ExecuteScalar();
conn.Close();
byte[] bytes = obj as byte[];
MemoryStream ms = new MemoryStream();
ms.Write(bytes,0,bytes.Length);
Image img = Image.FromStream(ms);
ms.Close();
this.pictureBox1.Image = img;
for (int i = 0; i < n; i++)
{
bytes=(byte[])ds.Tables[0].Rows[i][0]; //这条语句有没有问题?
}