Hi All,

Anyone know of an efficient way to read a data text file in comma delimited format and displaying the information to a table. I read some of the previous post, but they did not seem too informative.

Basically,

Check file existance, display if not availible
Load variables from file
Diplay variables to table

Hi All,

Anyone know of an efficient way to read a data text file in comma delimited format and displaying the information to a table. I read some of the previous post, but they did not seem too informative.

Basically,

Check file existance, display if not availible
Load variables from file
Diplay variables to table

hii!

just try the following code: hope it might help you! i have used the Microsoft Text Driver to read the content from the CSV file strieghtly & populating a Grid with the fetched data!

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dtRecords As DataTable
Dim dr As DataRow
dtRecords = GetDataTable("SELECT * FROM members2.csv")
DataGridView1.DataSource = dtRecords

End Sub

Private Function GetConnection()
Return "Driver={Microsoft Text Driver (*.txt; *.csv)};HDR=YES;Extensions=asc,csv,tab,txt;Dbq= " & Application.StartupPath & "\;"
End Function

Private Function GetDataTable(ByVal sql As String)
Dim rt As DataTable
Dim da As OdbcDataAdapter
Dim con As OdbcConnection
Dim cmd As OdbcCommand
Try
rt = New DataTable()
ds = New DataSet()
da = New OdbcDataAdapter()
con = New OdbcConnection(GetConnection())
cmd = New OdbcCommand(sql, con)
da.SelectCommand = cmd
da.Fill(ds)
rt = ds.Tables(0)
Label1.Text = "Records in the CSV:" + CStr(ds.Tables(0).Rows.Count)
Catch ex As Exception
rt = Nothing
MsgBox(ex.Message)
End Try
Return rt
End Function

regards,

Ammar.

;)

This is an asp forum, ammarcool...not .NET.

<%
set fso = server.createobject("scripting.filesystemobject")
set file = fso.opentextfile(server.mappath(".") & "/data.txt", 1)
data = file.readall()
file.close
lines = split(data, VbCrLf)

response.write "<table border=1>"

for each line in lines
	subline = split(line, ",")
	response.write "<tr>"
	for each val in subline
		response.write "<td>" & val & "</td>"
	next
	response.write "</tr>"
next

response.write "</table>"

set fso = nothing : set file = nothing
%>

Hi All,

Anyone know of an efficient way to read a data text file in comma delimited format and displaying the information to a table. I read some of the previous post, but they did not seem too informative.

Basically,

Check file existance, display if not availible
Load variables from file
Diplay variables to table

==>
hi,
i usually open the file in excel, manupulate the data as needed and then import the file into a table in autocad, using simple cut & paste.
best regards and succes
wim.

hi,
i usually open the file in excel, manupulate the data as needed and then import the file into a table in autocad, using simple cut & paste.
best regards and succes
wim.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.