Question: Display export file contents in datagrid

  • Thread starter Thread starter VB Programmer
  • Start date Start date
V

VB Programmer

I have a comma delimited export file with 10 columns. I want to display the
first 5 and the last 2 columns in a datagrid or table. Is there any way to
do this automatically? If not, does anyone have any ideas how I can do
this? Can I just feed it to a dataset and use it with normal ADO.NET?

Thanks!
 
VB Programmer
I have a comma delimited export file with 10 columns. I want to display the
first 5 and the last 2 columns in a datagrid or table. Is there any way to
do this automatically? If not, does anyone have any ideas how I can do
this? Can I just feed it to a dataset and use it with normal ADO.NET?
Yes using a datatable.

Beneath is an old sample how to make a datatable. You can splits the columns
in your csv file row by row using the split.

I hope this helps?

Cor

\\\
Dim dt As New DataTable("Jay")
dt.Columns.Add(New DataColumn("one", Type.GetType("System.Int32")))
dt.Columns.Add(New DataColumn("two", Type.GetType("System.String")))
Dim keys(0) As DataColumn
keys(0) = dt.Columns("Jay")
dt.PrimaryKey = keys
///
 
¤ I have a comma delimited export file with 10 columns. I want to display the
¤ first 5 and the last 2 columns in a datagrid or table. Is there any way to
¤ do this automatically? If not, does anyone have any ideas how I can do
¤ this? Can I just feed it to a dataset and use it with normal ADO.NET?
¤

You can specify the columns you want to display in your SQL statement. If you do not have a column
header in your text file, the default column names are F1, F2, F3 etc.

Dim ConnectionString As String
Dim SQLString As String

ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\TextFiles;" & _
"Extended Properties=""Text;HDR=NO;"""

SQLString = "Select F1, F2, F3, F4, F5, F9, F10 from ReportFile.txt"

Dim ConnectionText As New OleDb.OleDbConnection

ConnectionText.ConnectionString = ConnectionString

ConnectionText.Open()

Dim AdapterText As New OleDb.OleDbDataAdapter(SQLString, ConnectionText)

Dim DataSetText As New DataSet("TextFiles")
AdapterText.Fill(DataSetText, "ReportFile")

DataGrid1.SetDataBinding(DataSetText, "ReportFile")

ConnectionText.Close()


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
VB Programmer,

I do not know why I made this mistake, maybe it is to hot here at the
moment. See the sample from Paul. (Which I had as well).

Sorry

Cor
 
Back
Top