C#2.0 从sql server 中读取二进制图片
生活随笔
收集整理的這篇文章主要介紹了
C#2.0 从sql server 中读取二进制图片
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?1/**////?<summary>
?2????????///?顯示示帶圖片的記錄
?3????????///?</summary>
?4????????///?<param?name="sender"></param>
?5????????///?<param?name="e"></param>
?6????????private?void?button1_Click(object?sender,?EventArgs?e)
?7????????{
?8????????????string?sql?=?"";
?9????????????sql?=?"SELECT?OrName,OrTel,?Orimage?FROM?Organize??WHERE?OrID?=?1";?//
10????????????SqlConnection?conn?=?new?SqlConnection(DBConnectioin.conStr);??????????
11????????????SqlCommand?cmd?=?new?SqlCommand(sql,?conn);
12????????????conn.Open();
13????????????SqlDataReader?reader?=?cmd.ExecuteReader();
14????????????reader.Read();
15????????????this.textBox1.Text?=(string)?reader["OrName"];
16????????????textBox2.Text?=?(string)reader["OrTel"];
17????????????MemoryStream?ms?=?new?MemoryStream((byte[])reader["Orimage"]);
18????????????Image?image?=?Image.FromStream(ms,?true);
19
20????????????reader.Close();
21????????????conn.Close();
22????????????pictureBox1.Image?=?image;
23????????}
?2????????///?顯示示帶圖片的記錄
?3????????///?</summary>
?4????????///?<param?name="sender"></param>
?5????????///?<param?name="e"></param>
?6????????private?void?button1_Click(object?sender,?EventArgs?e)
?7????????{
?8????????????string?sql?=?"";
?9????????????sql?=?"SELECT?OrName,OrTel,?Orimage?FROM?Organize??WHERE?OrID?=?1";?//
10????????????SqlConnection?conn?=?new?SqlConnection(DBConnectioin.conStr);??????????
11????????????SqlCommand?cmd?=?new?SqlCommand(sql,?conn);
12????????????conn.Open();
13????????????SqlDataReader?reader?=?cmd.ExecuteReader();
14????????????reader.Read();
15????????????this.textBox1.Text?=(string)?reader["OrName"];
16????????????textBox2.Text?=?(string)reader["OrTel"];
17????????????MemoryStream?ms?=?new?MemoryStream((byte[])reader["Orimage"]);
18????????????Image?image?=?Image.FromStream(ms,?true);
19
20????????????reader.Close();
21????????????conn.Close();
22????????????pictureBox1.Image?=?image;
23????????}
總結
以上是生活随笔為你收集整理的C#2.0 从sql server 中读取二进制图片的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HDU 3934 Summer holi
- 下一篇: FindFirstVolume系列函数遍