Updateing a database table from a dataset

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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
    Jake Guest

  2. Similar Questions and Discussions

    1. How many dataBase tables can a dataSet table update via dataGrid?
      I would like to display data in a datagrid in which the source of the data is multiple database tables. The select statement in the command object...
    2. how to set visible table out of dataset?
      Hi, all. A Form has a DataGrid bound to a DataSet including two DataTable, A and B. When Form is loaded the two table is populated to DataSet and...
    3. Dataset to table
      Hi I have a dataset which is filled with data. How can I write this dataset into a local access table and also creating the table if it does not...
    4. Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset
      Hi All, I am facing problem in copying content of table from a untyped dataset into to a table inside the typed dataset. I wanted to copy the data...
    5. Dataset and table names.....
      I have a stored procedure that queries a sql server database and returns the multiple data tables ( 7 to be precise) these tables are the results of...
  3. #2

    Default Re: Updateing a database table from a dataset

    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" <reachJake@hotmail.com> wrote in message
    news:14c001c35bc1$c1817b50$7d02280a@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

    Steve Letford Guest

  4. #3

    Default Re: Updateing a database table from a dataset

    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" <reachJake@hotmail.com> wrote in message
    >news:14c001c35bc1$c1817b50$7d02280a@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
    >
    >
    >.
    >
    Jake Guest

  5. #4

    Default Re: Updateing a database table from a dataset

    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 [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

  6. #5

    Default Re: Updateing a database table from a dataset

    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" <reachJake@hotmail.com> wrote in message
    news:085201c35bd5$ab68ce40$a301280a@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" <reachJake@hotmail.com> wrote in message
    > >news:14c001c35bc1$c1817b50$7d02280a@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
    > >
    > >
    > >.
    > >

    Steve Letford Guest

  7. #6

    Default Re: Updateing a database table from a dataset

    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" <natty@dao2com.com> wrote in message
    news:eD6Uzl9WDHA.2064@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 [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Steve Letford Guest

  8. #7

    Default Re: Updateing a database table from a dataset

    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 [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur Guest

  9. #8

    Default Re: Updateing a database table from a dataset

    There you go Jake, 2 possible well reasoned methods.

    Take your pick.
    Thanks Natty

    Steve



    "Natty Gur" <natty@dao2com.com> wrote in message
    news:OJl$w2IXDHA.1204@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 [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Steve Letford Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139