WEB开发网
开发学院软件开发VB Sql Server中Image类型字段在VB.NET中的读写操作 阅读

Sql Server中Image类型字段在VB.NET中的读写操作

 2006-10-07 21:14:28 来源:WEB开发网   
核心提示: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.

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()

Tags:Sql Server Image

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接