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 }
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)