469,616 Members | 2,559 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,616 developers. It's quick & easy.

Displaying Text File in a Table

What is the easiest way to display in a table, a delimited
text data saved in a text file?

I need an idea so that I can research it!

Amjad
Nov 20 '05 #1
5 1301
Cor
Hi Amjad,

Just an idea to research

Use a "datatable" and a "datagrid" from which that datatable is the
datasource
(You need for the to create the datatable, the "datarow" 's and the
"datacolumn" 's )

Then you can read your text file using the "streamreader".

While reading record by record you "split" every row using the delimiter

For every row you read you make a datarow which you fill from the splitted
string array.

I think that if you have researched it, your text will be on your screen.

All the words between the "" are words you can look for on/in MSDN, there
are a lot of examples

I hope this was where you where looking for?

Cor
What is the easiest way to display in a table, a delimited
text data saved in a text file?

I need an idea so that I can research it!

Amjad

Nov 20 '05 #2
Assuming you have a Schema.ini file available for use you can use code like
this:

Public Sub FillTable(ByRef ds As DataSet, ByVal TableName As String, ByVal
Path As String)
Dim strConn, strSQL, strFileTitle, strFileFolder As String
strFileTitle = Path.GetFileName(Path )
strFileFolder = Path.GetDirectoryName(Path )

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
strConn &= "Data Source=" & strFileFolder & ";"
strConn &= "Extended Properties=Text"

strSQL = "SELECT * FROM [" & strFileTitle & "]"

Dim dt As DataTable
Dim da As OleDbDataAdapter
Dim cnn As New OleDbConnection(strConn)
Dim cmd As New OleDbCommand(strSQL, cnn)
Try
cmd.CommandType = CommandType.Text
cnn.Open()
da = New OleDbDataAdapter(cmd)
da.Fill(ds, TableName)
Finally
cnn.Close()
End Try
End Sub

--
Joe Fallon

"Amjad Farran" <an*******@discussions.microsoft.com> wrote in message
news:3c****************************@phx.gbl...
What is the easiest way to display in a table, a delimited
text data saved in a text file?

I need an idea so that I can research it!

Amjad

Nov 20 '05 #3
Assuming you have a Schema.ini file available for use you can use code like
this:

Public Sub FillTable(ByRef ds As DataSet, ByVal TableName As String, ByVal
Path As String)
Dim strConn, strSQL, strFileTitle, strFileFolder As String
strFileTitle = Path.GetFileName(Path )
strFileFolder = Path.GetDirectoryName(Path )

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
strConn &= "Data Source=" & strFileFolder & ";"
strConn &= "Extended Properties=Text"

strSQL = "SELECT * FROM [" & strFileTitle & "]"

Dim dt As DataTable
Dim da As OleDbDataAdapter
Dim cnn As New OleDbConnection(strConn)
Dim cmd As New OleDbCommand(strSQL, cnn)
Try
cmd.CommandType = CommandType.Text
cnn.Open()
da = New OleDbDataAdapter(cmd)
da.Fill(ds, TableName)
Finally
cnn.Close()
End Try
End Sub

--
Joe Fallon

"Amjad Farran" <an*******@discussions.microsoft.com> wrote in message
news:3c****************************@phx.gbl...
What is the easiest way to display in a table, a delimited
text data saved in a text file?

I need an idea so that I can research it!

Amjad

Nov 20 '05 #4
To display the results:
On a form just add a DataGrid and bind it to your datatable:

DataGrid1.DataSource = dsMain.Tables(strTableName).DefaultView
--
Joe Fallon

"Amjad Farran" <an*******@discussions.microsoft.com> wrote in message
news:3c****************************@phx.gbl...
What is the easiest way to display in a table, a delimited
text data saved in a text file?

I need an idea so that I can research it!

Amjad

Nov 20 '05 #5
To display the results:
On a form just add a DataGrid and bind it to your datatable:

DataGrid1.DataSource = dsMain.Tables(strTableName).DefaultView
--
Joe Fallon

"Amjad Farran" <an*******@discussions.microsoft.com> wrote in message
news:3c****************************@phx.gbl...
What is the easiest way to display in a table, a delimited
text data saved in a text file?

I need an idea so that I can research it!

Amjad

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Waguih Boctor | last post: by
4 posts views Thread by Stephen | last post: by
reply views Thread by Fronky | last post: by
3 posts views Thread by Al Wilkerson | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.