473,387 Members | 1,592 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,387 software developers and data experts.

Updateing a database table from a dataset

Hi all,
I am trying to update an SQL server table from a dataset
populated by an excel spread sheet. Each record has a
check box so it can be excluded from the SQL server table
population.

Does anyone now how I would acheive this, I don't want to
have to loop through each record in the dataset and do a
separate insert for each record as there can be allot of
records, and this would result in a waste for recourses.
I was hoping the dataset might have a method that can
perform a bulk insert.

Thanks in advance.

Jake
Nov 17 '05 #1
7 1116
You can do bulk updating using a dataadapter. However because you are
retrieving data from the excel sheet and updating another datasource then
you probably can't do that.

Also, the dataadapter would do an inefficient update as it tends to do more
joins than it needs to. You are probably better off and more efficient to
loop through each record using a datareader and doing the update. I think!

Steve

"Jake" <re*******@hotmail.com> wrote in message
news:14****************************@phx.gbl...
Hi all,
I am trying to update an SQL server table from a dataset
populated by an excel spread sheet. Each record has a
check box so it can be excluded from the SQL server table
population.

Does anyone now how I would acheive this, I don't want to
have to loop through each record in the dataset and do a
separate insert for each record as there can be allot of
records, and this would result in a waste for recourses.
I was hoping the dataset might have a method that can
perform a bulk insert.

Thanks in advance.

Jake

Nov 17 '05 #2
Hi steve,

Thanks for the feed back. I just seems there must be a
more efficient way considering if there is 10000 records
to be inserted ASP.Net has to continuously connect to the
DB 10,000 times. I have tried and it takes 30 seconds to
run, which is not too bad. I was hoping that there was
some sort of bulk insert?

Cheers Jake.

-----Original Message-----
You can do bulk updating using a dataadapter. However because you areretrieving data from the excel sheet and updating another datasource thenyou probably can't do that.

Also, the dataadapter would do an inefficient update as it tends to do morejoins than it needs to. You are probably better off and more efficient toloop through each record using a datareader and doing the update. I think!
Steve

"Jake" <re*******@hotmail.com> wrote in message
news:14****************************@phx.gbl...
Hi all,
I am trying to update an SQL server table from a dataset populated by an excel spread sheet. Each record has a
check box so it can be excluded from the SQL server table population.

Does anyone now how I would acheive this, I don't want to have to loop through each record in the dataset and do a separate insert for each record as there can be allot of records, and this would result in a waste for recourses. I was hoping the dataset might have a method that can
perform a bulk insert.

Thanks in advance.

Jake

.

Nov 17 '05 #3
Hi,

You can use Bulk insert with command object.

Sql = "insert into a values('0');insert into a values('1')";
SqlCommand oCmd = new SqlCommand(Sql,oConnection);
int i = oCmd.ExcecudeNonQuery();

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #4
Not as far as I'm aware. I think I'm correct in saying that even the
dataadapter, which gives the impression of a bulk insert is using a
datareader behind the scenes to do the insert.
As the data adapter doesn't know the datamodel, it has a rough guess on the
number of joins that it needs to do and therefore could be wrong as it may
join a number of different fields instead of perhaps just one that it needs.
Its been a while since I read all this but I'm pretty sure that I'm right.

I still think you'll need to loop through each record and do the insert, at
least that way you can put the inserts into a transaction.

Hope this helps.

Steve
"Jake" <re*******@hotmail.com> wrote in message
news:08****************************@phx.gbl...
Hi steve,

Thanks for the feed back. I just seems there must be a
more efficient way considering if there is 10000 records
to be inserted ASP.Net has to continuously connect to the
DB 10,000 times. I have tried and it takes 30 seconds to
run, which is not too bad. I was hoping that there was
some sort of bulk insert?

Cheers Jake.

-----Original Message-----
You can do bulk updating using a dataadapter. However

because you are
retrieving data from the excel sheet and updating

another datasource then
you probably can't do that.

Also, the dataadapter would do an inefficient update as

it tends to do more
joins than it needs to. You are probably better off and

more efficient to
loop through each record using a datareader and doing

the update. I think!

Steve

"Jake" <re*******@hotmail.com> wrote in message
news:14****************************@phx.gbl...
Hi all,
I am trying to update an SQL server table from a dataset populated by an excel spread sheet. Each record has a
check box so it can be excluded from the SQL server table population.

Does anyone now how I would acheive this, I don't want to have to loop through each record in the dataset and do a separate insert for each record as there can be allot of records, and this would result in a waste for recourses. I was hoping the dataset might have a method that can
perform a bulk insert.

Thanks in advance.

Jake

.

Nov 17 '05 #5
you'd still have to loop through each record and build up a huge sql
statment that would do the insert.

There are 2 problems with doing it this way, in my opinion:
1. The final sql statement would be huge for 1000 records. There might
even be problems trying execute a massive sql statement on the database.
2. I don't think you should do native sql statements on a database that is
allowing user input because you open yourself up to sql injection issues.
Therefore you'd have to parse each insert statement.

So, still reckon youre better off doing it the long way. Which, wouldn't
take too long anyway. The connection would only be open once while you loop
through the records and most of the time is taken up establishing the
connection.

Steve
"Natty Gur" <na***@dao2com.com> wrote in message
news:eD**************@TK2MSFTNGP11.phx.gbl...
Hi,

You can use Bulk insert with command object.

Sql = "insert into a values('0');insert into a values('1')";
SqlCommand oCmd = new SqlCommand(Sql,oConnection);
int i = oCmd.ExcecudeNonQuery();

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #6
Steve,

You absolute right but it still more efficient to reduce calls the DB.
You have to go through the records one way or another at lest you can
reduce calling DB from 1000 times to 100 times. Check for RPC and see it
for yourself.

I’m not SQL server expert but I know that oracle can execute bulk insert
parallel, if its holds true for SQL server this can also help your
performance.

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #7
There you go Jake, 2 possible well reasoned methods.

Take your pick.
Thanks Natty

Steve

"Natty Gur" <na***@dao2com.com> wrote in message
news:OJ**************@TK2MSFTNGP12.phx.gbl...
Steve,

You absolute right but it still more efficient to reduce calls the DB.
You have to go through the records one way or another at lest you can
reduce calling DB from 1000 times to 100 times. Check for RPC and see it
for yourself.

I'm not SQL server expert but I know that oracle can execute bulk insert
parallel, if its holds true for SQL server this can also help your
performance.

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #8

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

Similar topics

4
by: Frnak McKenney | last post by:
I'm using an in-core DataSet as an image of my application's 'database' (a multi-table Access97 mdb file). Updates are made to the DataTables within the DataSet via forms with bound TextBoxes,...
0
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a...
0
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database...
3
by: Newbie! | last post by:
Hi Group, How would one Update, Delete and Add a Table in VB.Net using a Access Database? Any Links would be appriciated Ta Si
2
by: Carl Summers | last post by:
I have a table in an Access database that has no sort applied in Access. When I fill a dataset with data from that table (the entire one dimensional table) my dataset is sorted differently than...
15
by: philip | last post by:
On a form, I have a datagridview. This datagridview is constructed on a dataset filled by a tableadapter. The table adapter do very well what it must do when filling dataset. Insertions,...
1
by: r2destini | last post by:
Hi Friends, I am new to .Net. So I don't know much. I am facing a problem in updating database through ADO.Net I am creating the dataset and there is no problem in the updation and...
1
by: DennisBetten | last post by:
First of all, I need to give some credit to Mahesh Chand for providing me with an excellent basis to export data to excel. What does this code do: As the title says, this code is capable of...
1
Curtis Rutland
by: Curtis Rutland | last post by:
How To Use A Database In Your Program Part II This article is intended to extend Frinny’s excellent article: How to Use a Database in Your Program. Frinny’s article defines the basic concepts...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
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
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,...
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,...

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.