Inserting Multiple records via loop

Posted on 2009-12-29
Last Modified: 2012-05-08
I need to create several records at one time using both data from a text box and from a query.  I created a button with the code-behind shown below and it works fine for creating numbered records.  The problem I am having is passing a value from the "GetVersionItemNoOnly" adapters into the insert statement.  Right now, the insert statement only uses an integer that index with each loop.  It need to pull a value from the 1st column of the row corresponding to the loop.  I attached a picture with some sample data to hopefully explain better.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim i As Integer

        Dim AuditQuestionCount As New LebWebTableAdapters._6SActiveQuestionsTableAdapter

        For i = 1 To AuditQuestionCount.GetVersionItemNoOnly.Count

            Dim NewAuditResultLine As New LebWebTableAdapters._6SAuditResultsTblTableAdapter

            NewAuditResultLine.InsertAuditResultQuery(DropDownList1.Text, i, Calendar1.SelectedDate, ListBox1.Text + ", " + ListBox2.Text + " & " + ListBox3.Text)


End Sub

Open in new window

Question by:Cldela0
    LVL 22

    Expert Comment


    Will suggest you to use sql insert statements for bulk insert.. If interested, can provide more details on this..

    Author Comment

    I would be interested in how to do that.  Thanks
    LVL 22

    Accepted Solution


    look at below code

    do while rs.EOF
      sql = sql & "INSERT INTO TABLENAME VALUES('a','a');"

    con.Execute sql

    this example is based on classic ASP.

    Let me know if you have further questions..

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now