Results 1 to 3 of 3

Thread: sql insert query for inserting mutliple records

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    73

    sql insert query for inserting mutliple records

    i have a listbox with more than one record, 2 textbox
    i want to insert the data from all 3 objects in the sql table but with the below code i am not able to insert it.

    eg suppose i have 2 names in listbox1 , name1, name 2 & in first textbox A & second textbox "1"
    against both the names the data of text box shld be insetred
    eg
    A name1 1
    A name2 1


    For i = 1 To ListBox1.Items.Count

    If ListBox1.Items(i - 1).selected = True Then

    strqry = "insert into trans(cid,pid,lid) values('" & textBox1.Text & "','" & ListBox1.Items(i - 1) & "','" & textBox2.Text & "')"
    cmd.CommandText = strqry
    cmd.ExecuteNonQuery()
    end if
    next

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: sql insert query for inserting mutliple records

    Try
    Code:
    Dim i As Integer
            For i = 0 To ListBox1.Items.Count - 1
                If ListBox1.GetSelected(i) = True Then
                   'execute insert query here
                End If
            Next

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2008
    Posts
    73

    Re: sql insert query for inserting mutliple records

    Quote Originally Posted by Hack
    Try
    Code:
    Dim i As Integer
            For i = 0 To ListBox1.Items.Count - 1
                If ListBox1.GetSelected(i) = True Then
                   'execute insert query here
                End If
            Next

    hi

    i tried the same but after the if listbox1................. statement the program comes to end if , it doesnt go thr' the execute statement

Posting Permissions

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



Click Here to Expand Forum to Full Width