【问题标题】:empty path name is not legal (vb.net 2005 ,access 2000,)空路径名不合法 (vb.net 2005 ,access 2000,)
【发布时间】:2015-01-22 09:55:57
【问题描述】:

[错误] 空路径名不合法 问题是我无法将图像插入 Access 数据库。哪一行是错误的。在此先感谢帮助我的人

问候, 菲祖尔

    Dim OpenFileDialog1 As New OpenFileDialog
    Dim fsreader As New IO.FileStream(OpenFileDialog1.FileName,IO.FileMode.Open, IO.FileAccess.Read)
    Dim breader As New IO.BinaryReader(fsreader)

    Dim imgbuffer(fsreader.Length) As Byte
    breader.Read(imgbuffer, 0, fsreader.Length)
    fsreader.Close()

    cnn.ConnectionString = "provider=microsoft.ace.oledb.12.0; data source = |datadirectory|\db1.accdb;"
    cnn.Open()
    Dim sql As String
    sql = "insert into Table1 Values(" & TextBox1.Text & ",'" & imgbuffer.Length & "')"
    Dim cmd As New OleDb.OleDbCommand(sql, cnn)
    cmd.ExecuteNonQuery()
    cmd.Dispose()
    cnn.Close()

【问题讨论】:

    标签: vb.net ms-access


    【解决方案1】:

    问题出在前两行:

    Dim OpenFileDialog1 As New OpenFileDialog
    Dim fsreader As New IO.FileStream(OpenFileDialog1.FileName,IO.FileMode.Open, IO.FileAccess.Read)
    

    您创建了一个 OpenFileDialog 实例,但您从未调用过它的 ShowDialog 方法,因此 FileName 属性为 Nothing。你需要这样的东西:

    Using OpenFileDialog1 As New OpenFileDialog
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            Dim fsreader As New IO.FileStream(OpenFileDialog1.FileName,IO.FileMode.Open, IO.FileAccess.Read)
            'remaining of code here
        End If
    End Using
    

    Using 语句确保对话框被正确处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多