VB.net 中的 CSV 文件和 OLEDB - 没有信息的异常
我正在尝试使用 VB 解析 ASP.NET 中用户提交的 csv 文件。这是我的函数:
Public Function getData() As DataSet
Dim conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetTempPath() + ";Extended Properties=""Text;HDR=No;FMT=Delimited"""
Dim cn As New OleDbConnection(conn)
Dim cmd As New OleDbCommand("SELECT * FROM " + sourceFile, cn)
Dim da As New OleDbDataAdapter(cmd)
cn.Open()
Dim dt As New DataSet()
da.Fill(dt)
cn.Close()
Return dt
End Function
我得到的错误是:
System.Data.OleDb.OleDbException was unhandled by user code
ErrorCode=-2147467259 消息 = IErrorInfo.GetDescription 失败,错误为 E_FAIL(0x80004005)。 源=系统.数据 堆栈跟踪: 在System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams,Object&executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object&executeResult) 在System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior行为,对象和executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior 行为,字符串方法) 在 System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior 行为) 在System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior行为) 在System.Data.Common.DbDataAdapter.FillInternal(DataSet数据集,DataTable []数据表,Int32 startRecord,Int32 maxRecords,字符串srcTable,IDbCommand命令,CommandBehavior行为) 在System.Data.Common.DbDataAdapter.Fill(数据集dataSet,Int32 startRecord,Int32 maxRecords,字符串srcTable,IDbCommand命令,CommandBehavior行为) 在System.Data.Common.DbDataAdapter.Fill(数据集数据集) 在 C:\Projects\Allied\App_Code\CSVReader.vb 中的 SuperSMITH.CSVReader.getData() 处:第 29 行 在 C:\Projects\Allied\tools\Step2.aspx.vb 中的tools_Step2.uplFile_FileUploadComplete(对象发送者,FileUploadCompleteEventArgs e)处:第58行 在 DevExpress.Web.ASPxUploadControl.ASPxUploadControl.OnFileUploadComplete(FileUploadCompleteEventArgs e) 在DevExpress.Web.ASPxUploadControl.ASPxUploadControl.RaiseFileUploadComplete(UploadedFile uploadedFile,字符串&errorText,字符串&callbackData) 在 DevExpress.Web.ASPxUploadControl.ASPxUploadControl.Validate() InnerException:
错误出现在 da.fill(dt)
行。
有什么建议吗?
I'm trying to parse a user-submitted csv file in ASP.NET with VB. Here is my function:
Public Function getData() As DataSet
Dim conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path.GetTempPath() + ";Extended Properties=""Text;HDR=No;FMT=Delimited"""
Dim cn As New OleDbConnection(conn)
Dim cmd As New OleDbCommand("SELECT * FROM " + sourceFile, cn)
Dim da As New OleDbDataAdapter(cmd)
cn.Open()
Dim dt As New DataSet()
da.Fill(dt)
cn.Close()
Return dt
End Function
the error I get is:
System.Data.OleDb.OleDbException was unhandled by user code
ErrorCode=-2147467259
Message=IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
Source=System.Data
StackTrace:
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at SuperSMITH.CSVReader.getData() in C:\Projects\Allied\App_Code\CSVReader.vb:line 29
at tools_Step2.uplFile_FileUploadComplete(Object sender, FileUploadCompleteEventArgs e) in C:\Projects\Allied\tools\Step2.aspx.vb:line 58
at DevExpress.Web.ASPxUploadControl.ASPxUploadControl.OnFileUploadComplete(FileUploadCompleteEventArgs e)
at DevExpress.Web.ASPxUploadControl.ASPxUploadControl.RaiseFileUploadComplete(UploadedFile uploadedFile, String& errorText, String& callbackData)
at DevExpress.Web.ASPxUploadControl.ASPxUploadControl.Validate()
InnerException:
The error comes up at the da.fill(dt)
line.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
出现的每个搜索结果都表明它必须使用 CSV 文件或
SELECT
语句中的保留关键字。sourceFile
的值是多少?Every search result that comes up says it has to do using reserved keywords in the CSV file or in the
SELECT
statement. What's the value ofsourceFile
?