程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> Visual Basic語言 >> VB綜合教程 >> Sql Server中Image類型字段在VB.NET中的讀寫操作

Sql Server中Image類型字段在VB.NET中的讀寫操作

編輯:VB綜合教程

  1.圖片文件寫入
              Dim tmpImg As image                    
              Dim r As DataRow                         
              Dim ms As New MemoryStream    
              Dim data() As Byte                         

              r = myDataSet.Tables(myTableName).NewRow
              tmpImg = Image.FromFile("c:xxx.jpg")
              tmpImg.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
              tmpImg.Dispose()
              ReDim data(ms.Length)
              ms.Position = 0
              ms.Read(data, 0, System.Convert.ToInt32(ms.Length))

              ...
              ...          
              r("pic") = data
              myDataSet.Tables(myTableName).Rows.Add(r)
              ...

  2.圖片數據的讀出
              Dim tmpImg As image                    
              Dim r As DataRow                         
              Dim ms As New MemoryStream    
              Dim data() As Byte                         
              Dim r As Integer

              data=myDataSet.Tables(myTableName).Rows(r).Item("pic")
              ms = New MemoryStream
              ms.Write(data(0), 0, data(0).GetUpperBound(0))
             
              '在窗體中顯示
              Me.pic0.Image = Image.FromStream(msImg(0))
             
              '存入到文件
              If  FileI.Exists("c:xxx.jpg") Then
                    File.Delete("c:xxx.jpg")
              End If
              fs = File.Create("c:xxx.jpg")
              fs.Write(data, 0, data.GetUpperBound(0))
              fs.Close()

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved