找不到文件'E:\ Programa \ DTR \ DTR \ bin \ Debug \ OpenFileDialog1

时间:2018-02-27 04:30:34

标签: vb.net ms-access

这是我的代码。

以下openfiledialog1的值。

If OpenFileDialog1.FileName <> Nothing Or OpenFileDialog1.FileName <> "" Then
   txtempname.Text = OpenFileDialog1.FileName.Substring(
       OpenFileDialog1.FileName.LastIndexOf("\") + 1,
       (OpenFileDialog1.FileName.IndexOf(".", 0) - (OpenFileDialog1.FileName.LastIndexOf("\") + 1)))
End If



Dim fsreader As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
Dim bread As New BinaryReader(fsreader)
Dim imgbuffer(fsreader.Length) As Byte
bread.Read(imgbuffer, 0, fsreader.Length)
fsreader.Close()

commstring = "Update EMPLOYEES SET EMPID=@EMPID, EMPNAME=@EMPNAME, DEPARTMENT=@DEPARTMENT, STATUS=@STATUS, pic_file=@picfile WHERE EMPID = @EMPID"

con.Open()

cmd = New OleDbCommand(commstring, con)

cmd.Parameters.AddWithValue("@EMPID", txtempno.Text)
cmd.Parameters.AddWithValue("@EMPNAME", txtempname.Text)
cmd.Parameters.AddWithValue("@DEPARTMENT", txtaddep.Text)
cmd.Parameters.AddWithValue("@STATUS", cbostat.Text)
cmd.Parameters.AddWithValue("@pic_file", imgbuffer)

cmd.ExecuteNonQuery()
con.Close()

1 个答案:

答案 0 :(得分:0)

您说的是If OpenFileDialog1.FileName而不是If Not OpenFileDialog1.FileName

我猜你试图获取没有扩展名的文件名?如果是这样,则不需要所有“IndexOf”。他是一个应该有帮助的简化版本。

    If Not OpenFileDialog1.FileName Is Nothing And Not OpenFileDialog1.FileName = "" Then
        txtempname.Text = Path.GetFileNameWithoutExtension(OpenFileDialog1.FileName)
    End If

Imports System.IO的{​​{1}})