473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Importing .csv file into a datatable VB.NET

How do you tell the .csv file that you are to import that it has no row
headers as I went to the web site http://www.connectionstrings.com/ and under
text file it says:

"HDR=Yes;" indicates that the first row contains columnnames, not data

So i have done HDR=No but this does not work as.
Nov 21 '05 #1
12 37876
Jonathan,

I did not try it however did you try not to use that parameter.

Cor
Nov 21 '05 #2
On Tue, 15 Mar 2005 09:33:04 -0800, "Jonathan" <Jo******@discussions.microsoft.com> wrote:

¤ How do you tell the .csv file that you are to import that it has no row
¤ headers as I went to the web site http://www.connectionstrings.com/ and under
¤ text file it says:
¤
¤ "HDR=Yes;" indicates that the first row contains columnnames, not data
¤
¤ So i have done HDR=No but this does not work as.

Perhaps you could post a sample of your text file structure?
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 21 '05 #3
Jonathan, what kind of results do you get using HDR=No ? If you set it to No, then Access will set the Column Names to:
Field1, Field2, Field3 etc. If that is not what you want, then you will have to set the Column/Field Names in code. Otherwise,
you will get the default names.
james
"Jonathan" <Jo******@discussions.microsoft.com> wrote in message news:E8**********************************@microsof t.com...
How do you tell the .csv file that you are to import that it has no row
headers as I went to the web site http://www.connectionstrings.com/ and under
text file it says:

"HDR=Yes;" indicates that the first row contains columnnames, not data

So i have done HDR=No but this does not work as.

Nov 21 '05 #4
My code:

Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\;Extended Properties=""Text;HDR=No;FMT=Delimited""")

Dim da As New OleDbDataAdapter()

Dim ds As New DataSet()

Dim cd As New OleDbCommand("SELECT * FROM C:\Test.csv, cn)

cn.Open()
da.SelectCommand = cd
ds.Clear()
da.Fill(ds, "CSV")
dg.DataSource = ds.Tables(0)
cn.Close()

Test.csv contains 13,472 rows but when it is opened in the datagrid it
returns 13,471 rows
"Paul Clement" wrote:
On Tue, 15 Mar 2005 09:33:04 -0800, "Jonathan" <Jo******@discussions.microsoft.com> wrote:

¤ How do you tell the .csv file that you are to import that it has no row
¤ headers as I went to the web site http://www.connectionstrings.com/ and under
¤ text file it says:
¤
¤ "HDR=Yes;" indicates that the first row contains columnnames, not data
¤
¤ So i have done HDR=No but this does not work as.

Perhaps you could post a sample of your text file structure?
Paul
~~~~
Microsoft MVP (Visual Basic)

Nov 21 '05 #5
What happens is instead of getting 13472 rows I get 13471 rows in the
datagrid. I am aware of Access doing this but I am working in VB.NET trying
to import a csv file into a datagrid.

"james" wrote:
Jonathan, what kind of results do you get using HDR=No ? If you set it to No, then Access will set the Column Names to:
Field1, Field2, Field3 etc. If that is not what you want, then you will have to set the Column/Field Names in code. Otherwise,
you will get the default names.
james
"Jonathan" <Jo******@discussions.microsoft.com> wrote in message news:E8**********************************@microsof t.com...
How do you tell the .csv file that you are to import that it has no row
headers as I went to the web site http://www.connectionstrings.com/ and under
text file it says:

"HDR=Yes;" indicates that the first row contains columnnames, not data

So i have done HDR=No but this does not work as.


Nov 21 '05 #6
Yes I tried not using the paramter but it didn't work

"Cor Ligthert" wrote:
Jonathan,

I did not try it however did you try not to use that parameter.

Cor

Nov 21 '05 #7
You're not using anything specific to .Net. You're using the exact same
thing that Access would use to open this CSV file. I'd recommend you
use a different parser. http://www.geocities.com/shriop/index.html

Nov 21 '05 #8
On Wed, 16 Mar 2005 01:27:06 -0800, "Jonathan" <Jo******@discussions.microsoft.com> wrote:

¤ My code:
¤
¤ Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
¤ Source=C:\;Extended Properties=""Text;HDR=No;FMT=Delimited""")
¤
¤ Dim da As New OleDbDataAdapter()
¤
¤ Dim ds As New DataSet()
¤
¤ Dim cd As New OleDbCommand("SELECT * FROM C:\Test.csv, cn)
¤
¤ cn.Open()
¤ da.SelectCommand = cd
¤ ds.Clear()
¤ da.Fill(ds, "CSV")
¤ dg.DataSource = ds.Tables(0)
¤ cn.Close()
¤
¤ Test.csv contains 13,472 rows but when it is opened in the datagrid it
¤ returns 13,471 rows

Which row is missing?
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 21 '05 #9
Jonathan, try changing :
dg.DataSource = ds.Tables(0)
to:
dg.DataSource = ds.Tables(0).DefaultView

Also, you might want to change this:
da.Fill(ds,"CSV")
to:
da.Fill(ds)

(both the above work for me)

I just compared what you are doing to some code in an application I have been working on that Imports CSV files to new Access
Database files and the lines above seems to be the only difference I can see. As Paul asked which row are you missing? It would
have to be either the first or the last one. Have you tried importing the CSV file into Access (build a new mdb & table) to see
if the missing row shows up there?
james

"Jonathan" <Jo******@discussions.microsoft.com> wrote in message news:B8**********************************@microsof t.com...
My code:

Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\;Extended Properties=""Text;HDR=No;FMT=Delimited""")

Dim da As New OleDbDataAdapter()

Dim ds As New DataSet()

Dim cd As New OleDbCommand("SELECT * FROM C:\Test.csv, cn)

cn.Open()
da.SelectCommand = cd
ds.Clear()
da.Fill(ds, "CSV")
dg.DataSource = ds.Tables(0)
cn.Close()

Test.csv contains 13,472 rows but when it is opened in the datagrid it
returns 13,471 rows
"Paul Clement" wrote:
On Tue, 15 Mar 2005 09:33:04 -0800, "Jonathan" <Jo******@discussions.microsoft.com> wrote:

¤ How do you tell the .csv file that you are to import that it has no row
¤ headers as I went to the web site http://www.connectionstrings.com/ and under
¤ text file it says:
¤
¤ "HDR=Yes;" indicates that the first row contains columnnames, not data
¤
¤ So i have done HDR=No but this does not work as.

Perhaps you could post a sample of your text file structure?
Paul
~~~~
Microsoft MVP (Visual Basic)

Nov 21 '05 #10
Still doesn't work

"james" wrote:
Jonathan, try changing :
dg.DataSource = ds.Tables(0)
to:
dg.DataSource = ds.Tables(0).DefaultView

Also, you might want to change this:
da.Fill(ds,"CSV")
to:
da.Fill(ds)

(both the above work for me)

I just compared what you are doing to some code in an application I have been working on that Imports CSV files to new Access
Database files and the lines above seems to be the only difference I can see. As Paul asked which row are you missing? It would
have to be either the first or the last one. Have you tried importing the CSV file into Access (build a new mdb & table) to see
if the missing row shows up there?
james

"Jonathan" <Jo******@discussions.microsoft.com> wrote in message news:B8**********************************@microsof t.com...
My code:

Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=C:\;Extended Properties=""Text;HDR=No;FMT=Delimited""")

Dim da As New OleDbDataAdapter()

Dim ds As New DataSet()

Dim cd As New OleDbCommand("SELECT * FROM C:\Test.csv, cn)

cn.Open()
da.SelectCommand = cd
ds.Clear()
da.Fill(ds, "CSV")
dg.DataSource = ds.Tables(0)
cn.Close()

Test.csv contains 13,472 rows but when it is opened in the datagrid it
returns 13,471 rows
"Paul Clement" wrote:
On Tue, 15 Mar 2005 09:33:04 -0800, "Jonathan" <Jo******@discussions.microsoft.com> wrote:

¤ How do you tell the .csv file that you are to import that it has no row
¤ headers as I went to the web site http://www.connectionstrings.com/ and under
¤ text file it says:
¤
¤ "HDR=Yes;" indicates that the first row contains columnnames, not data
¤
¤ So i have done HDR=No but this does not work as.

Perhaps you could post a sample of your text file structure?
Paul
~~~~
Microsoft MVP (Visual Basic)


Nov 21 '05 #11
First row

"Paul Clement" wrote:
On Wed, 16 Mar 2005 01:27:06 -0800, "Jonathan" <Jo******@discussions.microsoft.com> wrote:

¤ My code:
¤
¤ Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
¤ Source=C:\;Extended Properties=""Text;HDR=No;FMT=Delimited""")
¤
¤ Dim da As New OleDbDataAdapter()
¤
¤ Dim ds As New DataSet()
¤
¤ Dim cd As New OleDbCommand("SELECT * FROM C:\Test.csv, cn)
¤
¤ cn.Open()
¤ da.SelectCommand = cd
¤ ds.Clear()
¤ da.Fill(ds, "CSV")
¤ dg.DataSource = ds.Tables(0)
¤ cn.Close()
¤
¤ Test.csv contains 13,472 rows but when it is opened in the datagrid it
¤ returns 13,471 rows

Which row is missing?
Paul
~~~~
Microsoft MVP (Visual Basic)

Nov 21 '05 #12
On Fri, 18 Mar 2005 04:55:02 -0800, "Jonathan" <Jo******@discussions.microsoft.com> wrote:

¤ First row
¤

I have to say that this doesn't make any sense unless HDR is set to a value of YES. You're not using
a schema.ini file that would override this setting in the connection string are you? Are your column
names F1, F2, F3, etc?
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 21 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Emil Karlen | last post by:
Using the import-tag, a template appearing in the imported file, can be extended in the importing file. I am extending a template this way and in the main-file, inside the template use...
11
by: David Lozzi | last post by:
Hello, I need to automate importation of a excel file into a table. Here's my scenario: I'm writing an ASP.NET application where users can pull reports on imported data. The imported data is...
1
by: Tim Gains | last post by:
can someone instruct me as to how to load a binary file and the import it's data (rows pf data) into a database? Do I need to convert the binary file in any way in order to decipher it's data. Any...
6
by: gmarkowsky | last post by:
Hi all, I'm trying to import a class from a module. The class looks like this: class App: def __init__(self, master): frame = Frame(master) frame.pack()
6
by: owz | last post by:
I am trying 2 load details about cars from a.txt file and then display the total stock value off all cars. public class Car { // attributes private String manufacturer; private...
2
by: runway27 | last post by:
presently i have a table in which there are records and the fields are slno (this is a primary key auto increment), firstname, lastname, email, date(which inserts as a date format) these records are...
1
by: Sudhakar | last post by:
presently i have a table in which there are records and the fields are slno (this is a primary key auto increment), firstname, lastname, email, date(which inserts as a date format) these records...
5
by: thread | last post by:
hi all does anyone knows how to import/link a file that sits on a server for now everytime im trying to import,im getting a message connect to server but then it is cenceled any ideas
6
by: passionateforjava | last post by:
Hi All, I am using struts application wherein I need to import file for some purpose.I have used input type="file" for the same which goes like: <input type="file" id="uploadFile" name="uploadFile"...
2
by: squirrelknight | last post by:
Hello. I am new to Python. I've just installed version 3.0.1, which I will be using on a Linux box (which I am also new to), and need to use it to essentially call on several files of a specific...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.