1
Answer

reading a .csv or .txt file into a dataset

cwarner

cwarner

20y
2.2k
1
hi, I feel like I've tried every connection string possible to read in a .csv file..... I have copied my current code into this thread, any help would be great! I'm using the microsoft.data.odbc namespace, but if the system.data namespace works OK, I can use that too. If ext.Text = "csv" Then 'Connection string for a Text File Dim connectionstring As String Dim conn2 As New Microsoft.Data.Odbc.OdbcConnection Dim da2 As New Microsoft.Data.Odbc.OdbcDataAdapter Dim dt2 As System.Data.DataTable Dim ds2 As System.Data.DataSet connectionstring = "Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:\automated auditors\testdata" 'Query the Employees.txt file as a table conn2 = New Microsoft.Data.Odbc.OdbcConnection(connectionstring) Dim SQL As String = "SELECT * FROM invoicescsv.csv" ' Create connection object Dim cmd As New Microsoft.Data.Odbc.OdbcCommand(SQL) cmd.Connection = conn2 ' Open connection conn2.Open() da2 = New Microsoft.Data.Odbc.OdbcDataAdapter("SELECT * FROM invoicescsv.csv", conn2) ds2 = New System.Data.DataSet dt2 = ds2.Tables.Add("invoices") da2.Fill(dt2) conn2.Close() End If Thanks, Christy.

Answers (1)