如何解决VB.NET中的“空路径名称不合法”。 [英] How do I solved 'empty path name is not legal' in VB.NET .

查看:280
本文介绍了如何解决VB.NET中的“空路径名称不合法”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用vb.net在ms访问中保存带有图像的教师资料。



我尝试了什么:



i'm trying to save teachers profile with image in the ms access using vb.net.

What I have tried:

Public Overloads Function SaveMEMBER() As DataSet
      Return Me.SaveMEMBER("RFID")
  End Function
  Public Overloads Function SaveMEMBER(ByVal sortfield As String) As DataSet
      Dim OpenFileDialog1 As New OpenFileDialog
      Dim fsreader As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
      Dim breader As New BinaryReader(fsreader)
      Dim imgbuffer(fsreader.Length) As Byte
      breader.Read(imgbuffer, 0, fsreader.Length)
      fsreader.Close()
      Dim a As String
      Dim b As String
      b = Form4.lbldate.Text

      a = Form4.txtname.Text & ", " & Form4.txtmid.Text & " " & Form4.txtsur.Text & "."

      Dim conn As OleDb.OleDbConnection = GetConnection()
      Dim SQL As String

      Try
          SQL = "INSERT INTO PROFILE ( [RFID], [IDNUMBER], [NAME],  [GENDER], [POSITION], [BIRTHDATE], [AGE]," & _
          " [DATEENCODED],[PICTURE])VALUES ( RFID, IDNUMBER, NAME,  GENDER, POSITION, BIRTHDATE, AGE, DATEENCODED, PICTURE)"


          Dim cmd As New OleDb.OleDbCommand(SQL, conn)
          cmd.Parameters.Add(New OleDb.OleDbParameter("RFID", Form4.txtrfid.Text))
          cmd.Parameters.Add(New OleDb.OleDbParameter("IDNUMBER", Form4.txtid.Text))
          cmd.Parameters.Add(New OleDb.OleDbParameter("NAME", a))
          cmd.Parameters.Add(New OleDb.OleDbParameter("GENDER", Form4.cbogen.SelectedItem))
          cmd.Parameters.Add(New OleDb.OleDbParameter("POSITION", Form4.txtpos.Text))
          cmd.Parameters.Add(New OleDb.OleDbParameter("BIRTHDATE", Form4.txtbdate.Text))
          cmd.Parameters.Add(New OleDb.OleDbParameter("AGE", Form4.txtage.Text))
          cmd.Parameters.Add(New OleDb.OleDbParameter("DATEENCODED", b))
          acscmd.CommandText = strsql
          acscmd.Connection = acsconn
          acscmd.Parameters.AddWithValue("PICTURE", imgbuffer)
          conn.Open()
          cmd.ExecuteNonQuery()
          MessageBox.Show("New Member is added!")
          clear()
      Catch ex As Exception

          MsgBox("Error in connection!ID or PIN already exist!")
      Finally
          conn.Close()
          conn.Dispose()
      End Try

  End Function

推荐答案

嗯。

您创建一个OpenFileDialog,然后立即使用FileName属性。

但是你不要在任何时候都不向用户显示它!

由于用户没有看到它,他没有选择文件,因此FileName属性为空,并且你得到一个例外。

Um.
You create an OpenFileDialog, and then you immediately use the FileName property.
But you don't show it to the user at any point!
Since the user doesn't see it, he doesn't select a file, so the FileName property is empty, and you get an exception.
Dim OpenFileDialog1 As OpenFileDialog = New OpenFileDialog()

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
    Dim fsreader As FileStream = New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
    ...
End If


这篇关于如何解决VB.NET中的“空路径名称不合法”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆