Dataset question?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ppuniversal
    New Member
    • Feb 2007
    • 52

    Dataset question?

    Hi,
    I am developing an ASP .NET 2.0 application with code behind in VB.
    I have a dataset in which I have some data (1 table and around 200 rows) fetched from the Database.

    Now my query is as follows:

    I have to insert the value of this dataset to a table. I want to avoid using 200 insert statements (even in a loop). How can I achieve this efficiently.

    I am thinking to create dynamic insert queries and appending them using StringBuilder.a ppend() method. So than I have a big string containing all the insert statements, delimited by newline character. Then I am thinking of passing this long string to a Stored Procedure present in my SQL Server. By this method I will not have to hit database for every insert statement from my codebehind and all the insert statements will be executed from my stored procedure.

    Is this a proper idea. Or I should use some other method.

    Please let me know.

    Thanks
    Pawan
  • Brad Orders
    New Member
    • Feb 2008
    • 21

    #2
    Hi Pawan

    When you said "I have to insert the value of this dataset to a table", did you mean a database table? If so, are you (1) trying to update the databases with changes made by the user, or (2) are you transferring data from one table to another?

    If (1), then only update the rows that have been changed. If (2), try transferring the data from within SQL Server, and try and avoid sending the data via .NET.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      If you have an SqlDataAdapter (used to fill DataSet's nicely), you can supply UpdateCommand and InsertCommand to its properties and they will be fired as needed when data in the dataset changes.

      Comment

      • ppuniversal
        New Member
        • Feb 2007
        • 52

        #4
        Originally posted by manovich
        If you are using MS SQL then you can try the SqlBulkCopy class.
        I am using MS SQL Server.

        Thanks for the reply.
        Pawan

        Comment

        • ppuniversal
          New Member
          • Feb 2007
          • 52

          #5
          Originally posted by Plater
          If you have an SqlDataAdapter (used to fill DataSet's nicely), you can supply UpdateCommand and InsertCommand to its properties and they will be fired as needed when data in the dataset changes.
          Will this automatically insert/update the data in the dataset to the database?

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Originally posted by ppuniversal
            Will this automatically insert/update the data in the dataset to the database?
            Roughly. I believe there are events that fire (or are triggered), that you can attach a handler to, when it thinks it should be performing those INSERTs/UPDATEs.

            Comment

            Working...