資源描述:
《圖片顯示存取技術(shù)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、在winform中將圖片存入sqlserver,并從sqlserver中讀取并顯示在picturebox中游不遠(yuǎn)的魚@2004-12-0400:301,存入sqlserver?數(shù)據(jù)庫結(jié)構(gòu)?createtabletest?{????ididentity(1,1),????FImageimage?}1.1,在窗體中加一個(gè)OpenFileDialog控件,命名為ofdSelectPic1.2,在窗體上添加一個(gè)打開文件按鈕,添加如下單擊事件代碼:???Streamms;?byte[]picbyte;?//ofdSelectPi
2、c.ShowDialog();?if(ofdSelectPic.ShowDialog()==DialogResult.OK)?{??if((ms=ofdSelectPic.OpenFile())!=null)??{???//MessageBox.Show("ok");???picbyte=newbyte[ms.Length];???ms.Position=0;???ms.Read(picbyte,0,Convert.ToInt32(ms.Length));???//MessageBox.Show("讀取完畢!");??
3、?//連接數(shù)據(jù)庫???SqlConnectionconn=newSqlConnection();???conn.ConnectionString="DataSource=localhost;Database=test;UserId=sa;Pwd=sa";???SqlCommandcmd=newSqlCommand("UpdateImage",conn);???cmd.CommandType=CommandType.StoredProcedure;???cmd.Parameters.Add("@UpdateImage",
4、SqlDbType.Image);???cmd.Parameters["@UpdateImage"].Value=picbyte;???conn.Open();???cmd.ExecuteNonQuery();???conn.Close();???ms.Close();???}??}2,讀取并顯示在picturebox中2.1添加一個(gè)picturebox,名為ptbShow2.2添加一個(gè)按鈕,添加如下響應(yīng)事件:?????SqlConnectionconn=newSqlConnection();conn.Connecti
5、onString="DataSource=localhost;Database=test;UserId=sa;Pwd=sa";stringstrSql="selectFImagefromtestwhereid=1";SqlCommandcmd=newSqlCommand(strSql,conn);conn.Open();SqlDataReaderreader=cmd.ExecuteReader();???????reader.Read();MemoryStreamms=newMemoryStream((byte[])r
6、eader["FImage"]);Imageimage=Image.FromStream(ms,true);???????reader.Close();???????conn.Close();ptbShow.Image=image;Asp.Net在SqlServer中的圖片存取技術(shù)游不遠(yuǎn)的魚@2004-12-0400:27在使用asp.net將圖片上傳并存入SqlServer中,然后從SqlServer中讀取并顯示出來一,上傳并存入SqlServer數(shù)據(jù)庫結(jié)構(gòu)?createtabletest?{????ididenti
7、ty(1,1),????FImageimage?}?相關(guān)的存儲(chǔ)過程?CreateprocUpdateImage?(????@UpdateImageImage?)?As?InsertIntotest(FImage)values(@UpdateImage)?GO在UpPhoto.aspx文件中添加如下:8、"上傳">然后在后置代碼文件UpPhoto.aspx.cs添加btnAdd按鈕的單擊事件處理代碼:privatevoidbtnAdd_Click(objectsender,System.EventArgse){???????//獲得圖象并把圖象轉(zhuǎn)換為byte[]???????HttpPostedFileu