資源描述:
《c# winform 讀取oracle中blob字段圖片并且顯示到picturebox里,保存進庫》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、1.private?void?button2_Click(object?sender,?EventArgs?e)??2.{??3.????OracleConnection?conn?=?dbc.getConnection();//獲得conn連接??4.????try??5.????{??6.????????conn.Open();??7.????????OracleCommand?cmd?=?conn.CreateCommand();??8.????????cmd.CommandText?=?"S
2、ELECT?zp?FROM?kk.kkbj?WHERE?xh?=?2345?";//查詢獲得圖片流??9.??10.????????OracleDataReader?reader?=?cmd.ExecuteReader();//創(chuàng)建一個OracleDateReader對象???11.????????reader.Read();??12.??13.????????MemoryStream?ms?=?new?MemoryStream((byte[])reader["zp"]);??14.??15.???
3、?????Image?image?=?Image.FromStream(ms,?true);??16.??17.????????reader.Close();??18.????????conn.Close();??19.??20.????????pictureBox1.Image?=?image;??21.????}??22.????catch?(Exception?ee)??23.????{??24.????????MessageBox.Show(ee.Message.ToString());??
4、25.????}??26.??27.}??privatevoidbutton2_Click(objectsender,EventArgse){OracleConnectionconn=dbc.getConnection();//獲得conn連接try{conn.Open();OracleCommandcmd=conn.CreateCommand();cmd.CommandText="SELECTzpFROMkk.kkbjWHERExh=2345";//查詢獲得圖片流OracleDataReaderr
5、eader=cmd.ExecuteReader();//創(chuàng)建一個OracleDateReader對象reader.Read();MemoryStreamms=newMemoryStream((byte[])reader["zp"]);Imageimage=Image.FromStream(ms,true);reader.Close();conn.Close();pictureBox1.Image=image;}catch(Exceptionee){MessageBox.Show(ee.Message
6、.ToString());}}----------下邊是上傳和存入數(shù)據(jù)庫有asp.net和winform(轉(zhuǎn))----------------------------------本文總結(jié)如何在.NetWinform和.Netwebform(asp.net)中將圖片存入sqlserver中并讀取顯示的方法???1,使用asp.net將圖片上傳并存入SqlServer中,然后從SqlServer中讀取并顯示出來???一,上傳并存入SqlServer???數(shù)據(jù)庫結(jié)構(gòu)createtabletest{????
7、ididentity(1,1),????FImageimage}???相關(guān)的存儲過程CreateprocUpdateImage(????@UpdateImageImage)AsInsertIntotest(FImage)values(@UpdateImage)GO???在UpPhoto.aspx文件中添加如下:C#代碼?1.??2.8、?name="btnAdd"?runat="server"?Text="上傳">
?????然后在后置代碼文件UpPhoto.aspx.cs添加btnAdd按鈕的單擊事件處理代碼:C#代碼