110,539
社区成员
发帖
与我相关
我的任务
分享
protected void Button1_Click(object sender, EventArgs e)
{
//selectinfo();
ShowImage("select inamg from table_name");
}
private void ShowImage(string sql)
{
///得到你config里面配置的数据库连接字符串
string strCon = ConfigurationManager.AppSettings["coa"];
SqlConnection myConn = new SqlConnection(strCon);
SqlCommand cmd = new SqlCommand(sql, myConn);
myConn.Open();
byte[] b= (byte[])cmd.ExecuteScalar();
if(b.Length>0)
{
MemoryStream stream = new MemoryStream(b, true);
stream.Write(b, 0, b.Length);
pictureBox1.Image = new Bitmap(stream);
stream.Close();
}
myConn.Close();
}