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

前端之家收集整理的这篇文章主要介绍了用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,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,TempBytes.Length) FileStr.Close() End SubEnd Class

猜你在找的VB相关文章