非常急的一个问题????????????? 请问如何把Sqserver中的图片(image类型)读取出来并显示到Image控件上。求原代码。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Read to Byte array and instance a image object using the byte array // Get new file name string strFullName = dlgFBSave.SelectedPath; if( strFullName[strFullName.Length - 1] != '\\' ) strFullName += @"\"; strFullName += lsvFileInfo.SelectedItems[0].Text; string strQuery = "SELECT FileData FROM FileInfo " + " WHERE FileID = " + lsvFileInfo.SelectedItems[0].Tag.ToString(); SqlDataAdapter sqlDAdapter = new SqlDataAdapter(strQuery,sqlConn); DataSet sqlRecordSet = new DataSet(); byte[] bData = null; //Get file data from DB try { sqlDAdapter.Fill( sqlRecordSet, "FileInfo" ); foreach( DataRow dr in sqlRecordSet.Tables["FileInfo"].Rows) { if( dr["FileData"] != DBNull.Value ) bData = ( byte[] )dr["FileData"]; } } catch(SqlException sqlErr) { MessageBox.Show( sqlErr.Message ); } catch { MessageBox.Show( "Failed to read data from DB!" ); } sqlRecordSet.Dispose(); sqlDAdapter.Dispose(); if( bData != null ) { // Save file FileInfo fi = new FileInfo( strFullName ); if( !fi.Exists ) { //Create the file. using (FileStream fs = fi.Create()) { fs.Write( bData, 0, bData.Length); } } else { //Create the file. using (FileStream fs = fi.OpenWrite()) { fs.Write( bData, 0, bData.Length); } } } 上面是读取的方法。更详细的,可以看http://blog.csdn.net/knight94/archive/2006/03/24/637800.aspx 在image.aspx中写 SqlConnection Conn = new SqlConnection(strConn); SqlCommand cmd = new SqlCommand(); cmd.Connection = Conn; cmd.CommandText = "SELECT image1 FROM Image1"; Conn.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "image"); byte[] image = (byte[])ds.Tables["image"].Rows[0].ItemArray[0]; Response.Clear(); Response.BinaryWrite(image);然后把image的scr属性设为image.aspx 我是要显示在Image控件里啊,你这个image.aspx是从哪里来的哦,再说Image控件没有scr这个属性啊 我照你说的那样做了,但是从数据库中读出来的路径却显示在页面上,而image的src没有得到值 啊 【求助】怎么判断devexpress gridcontrol的数据被修改过 c#中有小数点数的相乘用什么数据类型啊???? 关于用户登录的问题 Winform 隐藏问题!!!! 問個很菜的問題,這種界面效果怎麼做? 怎样把数字小于8位的数字转换成8位的数字。 Enterprise Library for .NET Framework 2.0 - January 2006. 下载地址 兼散分 午饭时候的灵感,想付诸实施,请大家讨论 calendar 控件如何实现鼠标滑过时 弹出一个div。 Xamarin iOS开发实战上册 (内部资料) 求一正则表达式,匹配0001到9999 一个小问题
更详细的,可以看
http://blog.csdn.net/knight94/archive/2006/03/24/637800.aspx
SqlConnection Conn = new SqlConnection(strConn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = Conn;
cmd.CommandText = "SELECT image1 FROM Image1";
Conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "image");
byte[] image = (byte[])ds.Tables["image"].Rows[0].ItemArray[0];
Response.Clear();
Response.BinaryWrite(image);
然后把image的scr属性设为image.aspx