当我执行此代码时,我有错误(空路径名称不合法。) [英] When I execute this code ihave error (empty path name is not legal.)
本文介绍了当我执行此代码时,我有错误(空路径名称不合法。)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
吗?
这篇关于当我执行此代码时,我有错误(空路径名称不合法。)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文