473,598 Members | 2,978 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 37956
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******@discu ssions.microsof t.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******@discu ssions.microsof t.com> wrote in message news:E8******** *************** ***********@mic rosoft.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=Micr osoft.Jet.OLEDB .4.0;Data
Source=C:\;Exte nded Properties=""Te xt;HDR=No;FMT=D elimited""")

Dim da As New OleDbDataAdapte r()

Dim ds As New DataSet()

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

cn.Open()
da.SelectComman d = 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******@discu ssions.microsof t.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******@discu ssions.microsof t.com> wrote in message news:E8******** *************** ***********@mic rosoft.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******@discu ssions.microsof t.com> wrote:

§ My code:
§
§ Dim cn As New OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data
§ Source=C:\;Exte nded Properties=""Te xt;HDR=No;FMT=D elimited""")
§
§ Dim da As New OleDbDataAdapte r()
§
§ Dim ds As New DataSet()
§
§ Dim cd As New OleDbCommand("S ELECT * FROM C:\Test.csv, cn)
§
§ cn.Open()
§ da.SelectComman d = 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).De faultView

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******@discu ssions.microsof t.com> wrote in message news:B8******** *************** ***********@mic rosoft.com...
My code:

Dim cn As New OleDbConnection ("Provider=Micr osoft.Jet.OLEDB .4.0;Data
Source=C:\;Exte nded Properties=""Te xt;HDR=No;FMT=D elimited""")

Dim da As New OleDbDataAdapte r()

Dim ds As New DataSet()

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

cn.Open()
da.SelectComman d = 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******@discu ssions.microsof t.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

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

Similar topics

1
2085
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 "<apply-imports/> to trigger the template in the imported file. Now, the imported template takes a parameter. How can I pass a parameter to the template I am overriding (and triggering with <apply-imports/>). I have tried " <apply-imports> <with-param...
11
1877
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 pulled from an old UNIX based system, then converted to Excel. I want the user to be able to use the web app to select and upload the file to the server, then press a button to have the SQL server process the Excel file and import it. I know I can do...
1
1137
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 help is great help. Thanks.
6
2561
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
2419
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 String model;
2
2148
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 presenty being inserting from a html form. this works fine. i have additional data that is on paper and this paper data needs to be added to this table and the are numerous records that have to be inserted so executing an sql query from myphpadmin...
1
1523
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 are presenty being inserting from a html form. this works fine. i have additional data that is on paper and this paper data needs to be added to this table and the are numerous records that have to be inserted so executing an sql query from...
5
1455
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
4115
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" size="50"> I have the import button on which I have used onClick event to call javascript function submitValues() used to validate all the fields from the page which goes like: <input type="button" name="select" value="Import" class="CSSButton"...
2
1853
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 type within a directory and run an external program to convert them to a different type. So far I have figured out how to list files in a directory using os.listdir, but I was wondering, is there a way that I could list specific file types? For...
0
7981
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
7894
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8392
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6711
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectóplanning, coding, testing, and deploymentówithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5437
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3894
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3938
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2410
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.