存到sql2000中的exe重新读取后变无效的win32程序求助

lkclover 2014-05-07 02:55:26
请问下 exe程序 存到sql2000中后
再读出来 生成 exe 会变 无效的win32程序
是什么原因? 可以解决么?
为了做一个 自动更新exe的功能,因为在外网

用一下代码把exe存到数据库

'读取文件
Dim fs = New System.IO.FileStream(TextBox1.Text, IO.FileMode.Open, IO.FileAccess.Read)
Dim imgData(fs.Length - 1) As Byte
fs.Read(imgData, 0, fs.Length - 1)
fs.close()

Dim tempConnection As New SqlConnection
Dim tempAdapter As SqlDataAdapter
Dim tempDataset As New DataSet
'打开数据库连接,取出数据
tempConnection.ConnectionString = "Server=.;DataBase=hua_fx;Uid=sa;pwd=;"
tempConnection.Open()
tempAdapter = New SqlDataAdapter("SELECT * FROM T_hsxtsj where 目标文件='WindowsApplicationfx.exe'", tempConnection)
tempAdapter.Fill(tempDataset)
'更新数据
Dim cb As New SqlCommandBuilder(tempAdapter)
tempDataset = New DataSet
tempAdapter.Fill(tempDataset)
tempDataset.Tables(0).Rows(0).Item("文件") = imgData
tempDataset.Tables(0).Rows(0).Item("版本号") = Getcurversion(TextBox1.Text)
tempAdapter.Update(tempDataset)
tempConnection.Close()

用以下代码 读取
Dim tempConnection As New SqlConnection
Dim tempAdapter As SqlDataAdapter
Dim tempDataset As New DataSet
'打开数据库连接,取出数据
tempConnection.ConnectionString = "Server=.;DataBase=hua_fx;Uid=sa;pwd=;"
tempConnection.Open()
tempAdapter = New SqlDataAdapter("SELECT * FROM T_hsxtsj where 目标文件='WindowsApplicationfx.exe'", tempConnection)
tempAdapter.Fill(tempDataset)
tempConnection.Close()

If tempDataset.Tables(0).Rows.Count > 0 Then
'将文件保存到硬盘文件c:\2.jpg
Dim imgData() As Byte
imgData = tempDataset.Tables(0).Rows(0).Item("文件")
Dim fs As FileStream
fs = File.Create("d:\WindowsApplicationfx.exe", imgData.Length - 1)
fs.Write(imgData, 0, imgData.Length - 1)
fs.Close()

MsgBox("OK")
Else
MsgBox("NO")
End If



...全文
90 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ttsffgg 2014-05-07
  • 打赏
  • 举报
回复
fs.Read(imgData, 0, fs.Length - 1) 改成 fs.Read(imgData, 0, fs.Length ) 后面保存部分没看,不过应该也是类似的错误

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧