user3516774
user3516774

Reputation: 29

FROM clause of INSERT INTO throwing unhandled exception in VB

I'm running VB 2019, trying to import a CSV file into an Access database using this code:

Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + My.Settings.DataLoc + "\PassMan.accdb;Jet OLEDB:Database Password=" + My.Settings.Authentication + ";")
Dim command As OleDb.OleDbCommand = New OleDb.OleDbCommand()
conn.Open()

Dim cmd As New OleDbCommand("INSERT INTO Passwords SELECT * FROM [text;FMT=Delimited;HDR=yes;DATABASE=" + My.Settings.DataLoc + "\PassMan.accdb] AS " + Path.GetFileName(ReadFile), conn)
cmd.ExecuteNonQuery()

ReadFile is defined by the user as a filename based on an OpenFileDialog. The name of the file I provide at runtime exists. The database file exists and is available, not open by any other app (I've used the same conn code elsewhere in the app).

I get an unhandled exception in the FROM clause in the INSERT INTO statement:

System.NullReferenceException: 'Object reference not set to an instance of an object.' System.Exception.InnerException.get returned Nothing.

What's the problem? How do I solve it? I'm stuck!

Upvotes: 0

Views: 68

Answers (0)

Related Questions