我正在尝试读取 .csv 文件以将其内容导入 SQL 表
我收到错误:
ExecuteReader: Connection property has not been initialized.
在这段代码的最后一行:
Function ImportData(ByVal FU As FileUpload, ByVal filename As String, ByVal tablename As String) As Boolean
Try
Dim xConnStr As String = "Driver={Microsoft Text Driver (*.txt; *.csv)};dbq=" & Path.GetDirectoryName(Server.MapPath(filename)) & ";extensions=asc,csv,tab,txt;"
' create your excel connection object using the connection string
Dim objXConn As New System.Data.Odbc.OdbcConnection(xConnStr.Trim())
objXConn.Open()
Dim objCommand As New OdbcCommand(String.Format("SELECT * FROM " & Path.GetFileName(Server.MapPath(filename)), objXConn))
If objXConn.State = ConnectionState.Closed Then
objXConn.Open()
Else
objXConn.Close()
objXConn.Open()
End If
' create a DataReader
Dim dr As OdbcDataReader
dr = objCommand.ExecuteReader()