import data from csv file

F

Family Tree Mike

No one is likely to do that. You haven't specified the problem completely
enough for anyone. For example, are the columns of data well defined or do
you need to determine them at runtime by reading the CSV first? You are
more likely to get an answer if you show where you are stuck in your code.
If you ask for the entire answer without showing your attempt, it will be
more likely for others to think you simply want your homework done for you.

By the way, please don't multipost. There are other answers on
..Dotnet.General where you asked this.
 
R

rowe_newsgroups

First off, community support does not exist to solve your every
problem with no work from you. In general, I will give you (or
whoever) enough guidance to get started on the path to the solution,
but I will not do it for you, otherwise you will never learn. With
that said, I will honor your request and give you the steps you
requested, in a sarcastic tone.

Steps:

1) Buy a book on ADO.NET
2) Apply what you have learned to fix your problem.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 
G

Gillard

by just having a look at the code project web site and searching CSV you can
find what you are looking for
 
A

a

Dear friends

I'm not strong vb.net programmer I'm just take course and I want to learn
from you

And I have Excellent knowledge of access 2003 (Expert)

In access 2003 to import data from CSV file you just select file import and
select text

And all CSV file will import in a new table with some steps with the wizard



know I want just import data from CSV file to Access using VB.NET



by button in vb.net form just click this button the vb.net imports data from
csv file to access mdb file



Mr. Paul

Microsoft MVP (Visual Basic)



give me this code :





Dim AccessConn As New
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"
& _
"Data Source=C:\Test Files\db1 XP.mdb")

AccessConn.Open()

'New table
Dim AccessCommand As New System.Data.OleDb.OleDbCommand("SELECT *
INTO [TextFileTable] FROM
[Text;DATABASE=C:\Documents and Settings\...\My Documents\My
Database\Text].[Textfile.txt]",
AccessConn)
'Existing table
'Dim AccessCommand As New System.Data.OleDb.OleDbCommand("INSERT
INTO [TextFileTable] (F1,
F2, F3, F4, F5) SELECT F1, F2, F3, F4, F5 FROM [Text;DATABASE=C:\Documents
and Settings\...\My
Documents\My Database\Text].[Textfile.txt]", AccessConn)

AccessCommand.ExecuteNonQuery()
AccessConn.Close()





But there is error in the code I can't benefit form this code

The error in sql code



I'm edit this code like this but also there is error in sql code:



Dim cn As New OleDbConnection

cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=test.mdb;Persist Security Info=False"

cn.Open()

Dim cmd As New OleDbCommand

cmd.CommandText = ("SELECT * INTO [TextFileTable] FROM [Text;DATABASE=
E:\a.csv]")

cmd.Connection = cn


cmd.ExecuteNonQuery()

cn.Close()

==

Can you edit the code for me
 
C

Cor Ligthert [MVP]

a,

It is important that you tell us if you want to use an import in an existing
database or a new database table.

As you are an expert in Access, you would no the reason.

That there is nothing simple is probably because that Jet is a little bit
out of the focus and everything is now SQL Server, where is a simple
BulkCopy (Although I see that this will be replaced)

For OleDB you have in fact simple to get a DataSet using the connection and
the Fill from CSV and then use that DataSet by looping through the resulted
datatable and then update your database that you have filled first.

For the update you can simple use the commandbuilder.

Cor
 
C

Cor Ligthert[MVP]

no = know

Sorry

Cor


Cor Ligthert said:
a,

It is important that you tell us if you want to use an import in an
existing database or a new database table.

As you are an expert in Access, you would no the reason.

That there is nothing simple is probably because that Jet is a little bit
out of the focus and everything is now SQL Server, where is a simple
BulkCopy (Although I see that this will be replaced)

For OleDB you have in fact simple to get a DataSet using the connection
and the Fill from CSV and then use that DataSet by looping through the
resulted datatable and then update your database that you have filled
first.

For the update you can simple use the commandbuilder.

Cor
 
K

Kevin S Gallagher

Your best course of action is to research the task at hand using Google. My
approach would be to discover how to read the CSV file into a collection
which can be looped though for data correctness then when this is done use
OleDb components to store the data.



The best advice after searching and reading MSDN documentation is to ask
your question here supplement your question with snippets of code so the
experts here can assist you.



Why not break down the objective as follows; read a text file line by line
i.e. System.IO.StreamReader, Loop thru this data, parse the data perhaps
using Regular expressions followed by validating and pushing the data to the
Access database using OleDb components.

Good luck :)

a said:
Dear friends

I'm not strong vb.net programmer I'm just take course and I want to learn
from you

And I have Excellent knowledge of access 2003 (Expert)

In access 2003 to import data from CSV file you just select file import
and select text

And all CSV file will import in a new table with some steps with the
wizard



know I want just import data from CSV file to Access using VB.NET



by button in vb.net form just click this button the vb.net imports data
from csv file to access mdb file



Mr. Paul

Microsoft MVP (Visual Basic)



give me this code :





Dim AccessConn As New
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"
& _
"Data Source=C:\Test Files\db1 XP.mdb")

AccessConn.Open()

'New table
Dim AccessCommand As New System.Data.OleDb.OleDbCommand("SELECT *
INTO [TextFileTable] FROM
[Text;DATABASE=C:\Documents and Settings\...\My Documents\My
Database\Text].[Textfile.txt]",
AccessConn)
'Existing table
'Dim AccessCommand As New System.Data.OleDb.OleDbCommand("INSERT
INTO [TextFileTable] (F1,
F2, F3, F4, F5) SELECT F1, F2, F3, F4, F5 FROM
[Text;DATABASE=C:\Documents and Settings\...\My
Documents\My Database\Text].[Textfile.txt]", AccessConn)

AccessCommand.ExecuteNonQuery()
AccessConn.Close()





But there is error in the code I can't benefit form this code

The error in sql code



I'm edit this code like this but also there is error in sql code:



Dim cn As New OleDbConnection

cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=test.mdb;Persist Security Info=False"

cn.Open()

Dim cmd As New OleDbCommand

cmd.CommandText = ("SELECT * INTO [TextFileTable] FROM [Text;DATABASE=
E:\a.csv]")

cmd.Connection = cn


cmd.ExecuteNonQuery()

cn.Close()

==

Can you edit the code for me





















Gillard said:
by just having a look at the code project web site and searching CSV you
can find what you are looking for
 

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