用VB.NET 如果将任何文件以二进制形式保存在数据库,然后再从数据库读取出来

Imports System.IO
Imports System.Text
Imports System.Data.SqlClient
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim s As String = ""
        Dim FileStr As New FileStream("F:/模拟自动更新安装部署.msi", FileMode.Open, FileAccess.Read) '文件位置
        Dim TempBytes(FileStr.Length - 1) As Byte
        Dim idd As Integer = FileStr.Read(TempBytes, 0, FileStr.Length)
        FileStr.Close()

        Dim a As Integer = s.Length
        Dim connStr As String = "server=192.168.0.127;database=测试SQL;uid=sa;password="
        Dim conn As SqlConnection = DBHelp.DBConn(connStr)
        Dim ds As New DataSet()
        Dim dp As New SqlDataAdapter("SELECT * FROM 版本表 WHERE 1=0", conn)
        Dim aa As SqlCommandBuilder = New SqlCommandBuilder(dp)
        dp.Fill(ds)
        Dim DTR As DataRow = ds.Tables(0).NewRow()
        DTR("版本号") = "1.0.0.1"
        DTR("更新日期") = DateTime.Now.ToString()
        DTR("更新文件") = TempBytes
        ds.Tables(0).Rows.Add(DTR)
        dp.Update(ds)
        conn.Close()


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim connStr As String = "server=192.168.0.127;database=测试SQL;uid=sa;password="
        Dim conn As SqlConnection = DBHelp.DBConn(connStr)
        Dim ds As New DataSet()
        Dim dp As New SqlDataAdapter("SELECT * FROM 版本表", conn)
        Dim aa As SqlCommandBuilder = New SqlCommandBuilder(dp)
        dp.Fill(ds)
        Dim TempBytes() As Byte = ds.Tables(0).Rows(0)("更新文件")
        Dim FileStr As New FileStream("F:/模拟自动更新安装部署还原.msi", FileMode.Create, FileAccess.Write)
        FileStr.Write(TempBytes, 0, TempBytes.Length)
        FileStr.Close()
    End Sub
End Class

你可能感兴趣的:(用VB.NET 如果将任何文件以二进制形式保存在数据库,然后再从数据库读取出来)