2007-01-22

從DB中取出圖片轉存

Dim con As New SqlConnection _
       ("Server=YourServer;uid= ;pwd=;database=northwind")
      Dim da As New SqlDataAdapter _
       ("Select * From MyImages", con)
      Dim MyCB As SqlCommandBuilder = New SqlCommandBuilder(da)
      Dim ds As New DataSet()
      con.Open()
      da.Fill(ds, "MyImages")
      Dim myRow As DataRow
      myRow = ds.Tables("MyImages").Rows(0)
      Dim MyData() As Byte
      MyData = myRow("imgField")
      Dim K As Long
      K = UBound(MyData)
      Dim fs As New FileStream _
       ("C:\winnt\Gone Fishing2.BMP", FileMode.OpenOrCreate, _
        FileAccess.Write)
      fs.Write(MyData, 0, K)
      fs.Close()
      fs = Nothing
      MyCB = Nothing
      ds = Nothing
      da = Nothing
      con.Close()
      con = Nothing
      MsgBox ("Image retrieved")

沒有留言:

張貼留言