From: great stuff on 2 Nov 2009 08:31 I am trying to import a textfile into datagridview 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 the text file (i .e., setting quotes to each number in the text file for eg., "01") how can this be done?? Is there any other way to do this ?? Thanks for any suggestion...
From: Sergey Poberezovskiy on 4 Nov 2009 22:48 If you know your table structure in advance, you can create a DataTable with the first text field, and pass it into the DataAdapter - this way the formatting should be preserved: Dim table As New DataTable() With table.Columns .Add("FirstColumn", GetType(String)) ' add the rest of the columns End With MyCommand.Fill(table) I have not tested this, but relatively sure it will work - let me know if it does not. "great stuff" wrote: > I am trying to import a textfile into datagridview 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 the text file (i .e., setting quotes to each number > in the text file for eg., "01") how can this be done?? > Is there any other way to do this ?? > > Thanks for any suggestion... > . >
|
Pages: 1 Prev: How to Make a .NET Timer Always Fire at the Right Time Next: Type question |