当我执行此代码时,我有错误(空路径名称不合法。)

问题描述:

Dim fd As New OpenFileDialog
       Dim fullFileName() As String = fd.FileName.Split("\")
       Dim fname As String = fullFileName.Last.ToString
       Dim fileContent() As Byte

       Dim fstream As New FileStream(fd.FileName, FileMode.Open)
       Dim Breader As New BinaryReader(fstream)
       fileContent = Breader.ReadBytes(fstream.Length)
       fstream.Close()
       Breader.Close()
       Dim cmd As New SqlCommand
       With cmd
           .Connection = conn
           .Parameters.Clear()
           .CommandText = "insert into TbPdf (fileName,fileData) values (@fileName, @fileData)"
           .CommandType = CommandType.Text
           .Parameters.AddWithValue("@fileName", fname)
           .Parameters.AddWithValue("@fileID", fileContent)
           conn.Open()
           .ExecuteNonQuery()
       End With
       MsgBox("تم  الحفظ")





我尝试过:



我的代码有什么问题

i希望在数据库sql server中保存文件并恢复它



What I have tried:

what is wrong in my code
i want save file in database sql server and restore it

嗯。

查看你的代码:

Um.
Look at your code:
Dim fd As New OpenFileDialog
Dim fullFileName() As String = fd.FileName.Split("\")

fd是一个 OpenFileDialog - 因此它从未被呈现给用户,它从未选择过文件,因此它没有文件名。你的意思是在某个时候打电话给 fd.ShowDialog 吗?