Read Data from text using OLEDB in VB.NET 2005

G

great stuff

I am trying to import a textfile using oledbconnection.

Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter

MyConnection = New System.Data.OleDb.OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & connectionString &
";Extended Properties='text;HDR=No;FMT=TabDelimited'")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [" &
fileName & "]", MyConnection)

DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet, "TextFile")
DataGridView1.DataSource = DtSet


but the values get formatted in this case
if i have the text file as below:
01
02
03
04

i get as below:
1
2
3
4

Without formatting how can this be done..
 
R

Rich P

01 02 03

will be interpreted as a number with a leading zero which will be
ignored. To override this behavior you need to surround your values
with double quotes

"01" "02" "03"

then in your datagridview control you will see

01 02 03

Rich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top