从插入条款到在VB中抛出未经手的例外
我正在运行VB 2019,试图使用此代码将CSV文件导入访问数据库中:
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由用户定义为基于OpenFileDialog的文件名。我在运行时提供的文件的名称存在。数据库文件存在并且可用,没有其他任何应用程序打开(我在应用程序中其他地方使用了相同的conn代码)。
我在插入语句中的“从子句中”中获得了一个未指导的例外:
system.nullReferenceException:“对象引用未设置为对象的实例。” system.exception.innerexception.get什么都没有返回。
有什么问题?我该如何解决?我卡住了!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论