日期:2014-05-18 浏览次数:20477 次
string sqlText = "select pic,msg from WapPushMsg where id = " + id; Odbc o = new Odbc(); byte[] photo = null; using (OdbcDataReader dr = o.ExecuteReader(sqlText)) { if (dr.Read()) { msgView.Text = dr[1].ToString(); if (!dr.IsDBNull(0)) { photo = (Byte[])dr[0]; } else { } } }
private void LoadImage(string fileName) { using (SqlConnection conn = new SqlConnection(connectionString)) { string sql = "select blobdata from Image where ImageFileName like @filename"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.Add("@filename", SqlDbType.Text); cmd.Parameters["@filename"].Value = fileName; conn.Open(); object objImage = cmd.ExecuteScalar(); byte[] buffer = (byte[])objImage; BinaryWriter bw = new BinaryWriter(new FileStream("C:\\abcd.png", FileMode.Create)); bw.Write(buffer); bw.Close(); MemoryStream ms = new MemoryStream(buffer); Image bgImage = Image.FromStream(ms); ms.Close(); this.BackgroundImage = bgImage; } }
------解决方案--------------------
pic字段类型是二进制的吗