473,473 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to import a csv file into database table using vb.net

I need to import a .csv file into a firebird database. I am able to
cnnect tothe databe using:
Dim ds1 As New DataSet
Dim SQLString As String = "insert into rdstype27
(division,trans_code,DATE,TIME,dept,vend,emp_no,on line_function,sku_del_units,
sku_handling_class, sku_no, loc, qty, retail,dc_sort_code,dc)
values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
Dim constringa As String =
"User=DBADMIN;Password=admin;Database=E:\Fireb ird
\RDS.FDB;DataSource=fs000xveuc90;Port=3050;Dialect =3;Charset=NONE;Role=user;Connection
lifetime=0;Connection timeout=15;Pooling=True;Packet Size=8192;Server
Type=0"
Dim FBcn As New
FirebirdSql.Data.FirebirdClient.FbConnection(const ringa)
Dim da As New
FirebirdSql.Data.FirebirdClient.FbDataAdapter(SQLS tring, FBcn)
Dim cmdBuilder As
FirebirdSql.Data.FirebirdClient.FbCommandBuilder = New
FirebirdSql.Data.FirebirdClient.FbCommandBuilder(d a)
Dim dtRecords1 As New DataTable
Dim InsertCmd As FirebirdSql.Data.FirebirdClient.FbCommand =
New FirebirdSql.Data.FirebirdClient.FbCommand
FBcn.Open()

Then I can parse the file using:
Using parser As New FileIO.TextFieldParser("e:\firebird
\actblrds027rl.txt")
parser.SetDelimiters(",")
Try

While Not parser.EndOfData
Me.DataGridView1.Rows.Add(parser.ReadFields())

End While
Beep()
MsgBox("Import Successfull!!")
Catch ex As Exception
MsgBox(e.ToString)
End Try

End Using
I need to get the data that is in the datagridview into the database.
Please help

Feb 8 '07 #1
4 17508
Why don't you just open the file with a datatable, then update the
database from the dataset?

T

Rnt6872 wrote:
I need to import a .csv file into a firebird database. I am able to
cnnect tothe databe using:
Dim ds1 As New DataSet
Dim SQLString As String = "insert into rdstype27
(division,trans_code,DATE,TIME,dept,vend,emp_no,on line_function,sku_del_units,
sku_handling_class, sku_no, loc, qty, retail,dc_sort_code,dc)
values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
Dim constringa As String =
"User=DBADMIN;Password=admin;Database=E:\Fireb ird
\RDS.FDB;DataSource=fs000xveuc90;Port=3050;Dialect =3;Charset=NONE;Role=user;Connection
lifetime=0;Connection timeout=15;Pooling=True;Packet Size=8192;Server
Type=0"
Dim FBcn As New
FirebirdSql.Data.FirebirdClient.FbConnection(const ringa)
Dim da As New
FirebirdSql.Data.FirebirdClient.FbDataAdapter(SQLS tring, FBcn)
Dim cmdBuilder As
FirebirdSql.Data.FirebirdClient.FbCommandBuilder = New
FirebirdSql.Data.FirebirdClient.FbCommandBuilder(d a)
Dim dtRecords1 As New DataTable
Dim InsertCmd As FirebirdSql.Data.FirebirdClient.FbCommand =
New FirebirdSql.Data.FirebirdClient.FbCommand
FBcn.Open()

Then I can parse the file using:
Using parser As New FileIO.TextFieldParser("e:\firebird
\actblrds027rl.txt")
parser.SetDelimiters(",")
Try

While Not parser.EndOfData
Me.DataGridView1.Rows.Add(parser.ReadFields())

End While
Beep()
MsgBox("Import Successfull!!")
Catch ex As Exception
MsgBox(e.ToString)
End Try

End Using
I need to get the data that is in the datagridview into the database.
Please help

Feb 9 '07 #2
Hi,

If you are sure that the records with the primary key don't already exist,
than you can just create SQL insert code and proces that using the
OleDbCommand.ExecuteNonQuery

Cor

"Rnt6872" <r_******@msn.comschreef in bericht
news:11**********************@v45g2000cwv.googlegr oups.com...
>I need to import a .csv file into a firebird database. I am able to
cnnect tothe databe using:
Dim ds1 As New DataSet
Dim SQLString As String = "insert into rdstype27
(division,trans_code,DATE,TIME,dept,vend,emp_no,on line_function,sku_del_units,
sku_handling_class, sku_no, loc, qty, retail,dc_sort_code,dc)
values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
Dim constringa As String =
"User=DBADMIN;Password=admin;Database=E:\Fireb ird
\RDS.FDB;DataSource=fs000xveuc90;Port=3050;Dialect =3;Charset=NONE;Role=user;Connection
lifetime=0;Connection timeout=15;Pooling=True;Packet Size=8192;Server
Type=0"
Dim FBcn As New
FirebirdSql.Data.FirebirdClient.FbConnection(const ringa)
Dim da As New
FirebirdSql.Data.FirebirdClient.FbDataAdapter(SQLS tring, FBcn)
Dim cmdBuilder As
FirebirdSql.Data.FirebirdClient.FbCommandBuilder = New
FirebirdSql.Data.FirebirdClient.FbCommandBuilder(d a)
Dim dtRecords1 As New DataTable
Dim InsertCmd As FirebirdSql.Data.FirebirdClient.FbCommand =
New FirebirdSql.Data.FirebirdClient.FbCommand
FBcn.Open()

Then I can parse the file using:
Using parser As New FileIO.TextFieldParser("e:\firebird
\actblrds027rl.txt")
parser.SetDelimiters(",")
Try

While Not parser.EndOfData
Me.DataGridView1.Rows.Add(parser.ReadFields())

End While
Beep()
MsgBox("Import Successfull!!")
Catch ex As Exception
MsgBox(e.ToString)
End Try

End Using
I need to get the data that is in the datagridview into the database.
Please help

Feb 9 '07 #3
uh 'BULK INSERT'?

why use a bunhc of VB code that's going to change every 18 months?

BULK INSERT works perfectly; right?

-Aaron

Feb 10 '07 #4
i agree dog

use BULK INSERT
it's a _LOT_ faster than inserting a single record at a time

if you don't know enough about databases; why don't you go back to
preschool

Feb 10 '07 #5

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

Similar topics

3
by: Szaki | last post by:
I must import some exemplary file to database (MS Srrver 2000) ofcourse using procedure Transact SQL. This file must: 1.Read the xml file 2. Create table 3. Import this date from xml file to my...
4
by: news | last post by:
Our production database in an exported textfil runs about 60 MB. Compressed that's about 9 MB. I'm trying to import the export into another machine running FC3 and mySQL 11.18, and it appears as...
1
by: Dan | last post by:
Could someone please help me with auto importing a series of data files into an Access table. I tried to follow code given below in a previous messagebut i'm getting error messages. Here's my...
4
by: Neil10365 | last post by:
I wonder if someone can help me with a small conundrum I am having. This is what I want to achieve: Scenario -------- Each week, I import an excel spreadsheet called Week1.xls into an access...
3
by: fkulaga | last post by:
Hi all, I have a problem with the issue in the subject, i have all data in one big excel file, in a denormalized form, and on the other side, i have mysql database with many tables, which is...
3
by: ninrulz | last post by:
I will try to explain my situation. I know that it is hard to offers solutions without fully understanding what people would like to achieve. I receive 2 csv files every month. The csv files...
7
by: Randy | last post by:
Folks: We have a web-based app that's _really_ slowing down because multiple clients are writing their own private data into a single, central database. I guess the previous programmer did...
7
by: perryche | last post by:
Is there a way with MS Access 2002 and above to prevent people importing from a blank Database the tables in another database? I have done a lot of searches but there isn't really a solution that...
9
by: a | last post by:
Dear friends I want import data from CSV file to mdb file How can I do that in vb.net?
6
by: provor | last post by:
Hello, I have the following code that I am using when a user presses a button to import an excel file into a table. The code is hard coded to point to the correct table. This works great for this...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
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...
0
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...
0
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 ...

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.