Following script generates error:
Dim Conn As System.Data.Odbc.OdbcConnection,dt as datatable
Dim da As System.Data.Odbc.OdbcDataAdapter
Dim strConnstr,strImportfolder,strFilename as string
Microsoft Text Driver requires the folder in which the CSV file resides to initialize
strImportFolder = "c:\importfile" '
this is the folder in which the file resides
strFileName = "csvimport.csv"
'this is the csv file to be imported
strConnStr = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + strImportFolder + ";"
Conn = New Odbc.OdbcConnection(strConnStr)
Note that we haven't supplied the CSV file name yet, we have supplied only the folder name, the file name is required when we query the CSV file.
--------------------------
Querying CSV File
--------------------------
We have initialized the connection object the querying syntax is as follows
Select * from [csvfile]
Since we have supplied the folder name already it is enough we supply only the filename when querying.
da = New System.data.Odbc.OdbcDataAdapter("select * from [" + strFileName + "]", conn)
da.Fill(dt)
-------------------------------------------
end
-------------------------------------------
Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: dataTable
Line xxx: da.Fill(dt)
... this code seems simple enough, any ideas of why it is breaking?
PS. Code was borrowed from
Authour: Author: Muralidharan Ramakrishnan
Dim Conn As System.Data.Odbc.OdbcConnection,dt as datatable
Dim da As System.Data.Odbc.OdbcDataAdapter
Dim strConnstr,strImportfolder,strFilename as string
Microsoft Text Driver requires the folder in which the CSV file resides to initialize
strImportFolder = "c:\importfile" '
this is the folder in which the file resides
strFileName = "csvimport.csv"
'this is the csv file to be imported
strConnStr = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + strImportFolder + ";"
Conn = New Odbc.OdbcConnection(strConnStr)
Note that we haven't supplied the CSV file name yet, we have supplied only the folder name, the file name is required when we query the CSV file.
--------------------------
Querying CSV File
--------------------------
We have initialized the connection object the querying syntax is as follows
Select * from [csvfile]
Since we have supplied the folder name already it is enough we supply only the filename when querying.
da = New System.data.Odbc.OdbcDataAdapter("select * from [" + strFileName + "]", conn)
da.Fill(dt)
-------------------------------------------
end
-------------------------------------------
Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: dataTable
Line xxx: da.Fill(dt)
... this code seems simple enough, any ideas of why it is breaking?
PS. Code was borrowed from
Authour: Author: Muralidharan Ramakrishnan