Click here to Skip to main content
14,664,409 members
Rate this:
Please Sign up or sign in to vote.
See more:
Dear members,

I am reading textfile into datagridview with following code

Dim Conn As System.Data.Odbc.OdbcConnection
Dim dt As New DataTable

Dim da As System.Data.Odbc.OdbcDataAdapter
Dim strConnstr, strImportFolder, strFilename, Filename As String

strImportFolder = "C:\"
strFilename = "abc" & "#txt"
strConnstr = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" & strImportFolder & "\;FMT=Delimited','"

Conn = New Odbc.OdbcConnection(strConnstr)

da = New Odbc.OdbcDataAdapter("Select * from[" + strFilename + "]", Conn)


but i got opuput as whole line only(without omitting ",")

123,abc,xyz (Its only one line)

but i want only

Please help me,

Thank you.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

I don't see anything particularly wrong with your code: this works for me
Dim strConnect As String = "Driver={Microsoft Text Driver (*.txt;*.csv)};Dbq=D:\Temp\;Extensions=asc,csv,tab,txt;Persist Security Info=False;Fmt=Delimited"
Dim dt As New DataTable()
Using con As New OdbcConnection(strConnect.Trim())
	Using obj_oledb_da As New OdbcDataAdapter("select * from [contactsShort.csv]", con)
	End Using
End Using
dataGridView1.DataSource = dt
Have you checked your data file? What does it's first line look like?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100