求教关于vb.net在sql下载二进制文件的问题。
代码的主要作用是 下载SQL表里面储存的二进制文件,我写的这个代码的思路是先查询数据 在DataGridView2中显示查询结果,然后在下载表格“文件保存”里面保存的文件,这种方法太笨了 我想改一下代码 不用DataGridView2直接后台查询并下载 这个我应该怎么改啊 我找不到方法了呢?谁能帮我改下?代码如下:
'显示查询
'------------------------
Dim mySelectQuery As String = "Select * from 模板管理"
Dim s As New StringBuilder
mySelectQuery = "Select * from 模板管理 Where 模板名称 = '导入新预留号.xls'"
Dim command As New SqlCommand(mySelectQuery)
command.CommandType = CommandType.Text
command.Connection = con
Dim dr As New SqlDataAdapter
dr.SelectCommand = command
Dim ds As New DataSet
ds = New DataSet()
dr.Fill(ds, "模板管理")
DataGridView2.DataSource = ds
DataGridView2.DataMember = "模板管理"
Me.DataGridView2.Columns("文件保存").Visible = False '不显示这一项
'------------------------
'下载文件
Dim fn As String
Dim MyFileName As String
fn = "导入新预留号.xls"
SaveFileDialog1.Filter = "所有文件|*.*"
SaveFileDialog1.FilterIndex = 1
SaveFileDialog1.FileName = fn
If SaveFileDialog1.ShowDialog() = DialogResult.Cancel Then
Exit Sub
End If
MyFileName = Me.SaveFileDialog1.FileName.Trim
Try
Dim wordData() As Byte
wordData = Me.DataGridView2.CurrentRow.Cells("文件保存").Value
Dim fs As FileStream
fs = File.Create(MyFileName, wordData.Length - 1)
fs.Write(wordData, 0, wordData.Length - 1)
fs.Close()
MessageBox.Show("下载成功!", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try --------------------编程问答-------------------- 没人知道嘛? --------------------编程问答-------------------- 谁帮我解答啊? --------------------编程问答-------------------- 除
补充:.NET技术 , VB.NET