1 Replies - 2163 Views - Last Post: 18 January 2012 - 05:23 AM Rate Topic: -----

#1 Kurochan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-January 12

saving all item in listbox(vb2010) in sql2005 database

Posted 18 January 2012 - 12:28 AM

please help me ....not all in the listbox items are save in database....only the index 0 is saved in the database...i want all to be save in database...heres my code T_T THANKS





        Try


            Dim SqlCom As SqlCommand


            If connection2.State = ConnectionState.Closed Then
                connection2.Open()
            End If

            'Initialize SQL Server Connection 

            Dim querySql0 As String = "INSERT INTO Registeredprof (SubjectandSectionandYear) VALUES (@SubjectandSectionandYear)"
           
            For i As Integer = 0 To ListBox2.Items.Count - 1




                SqlCom = New SqlCommand(querySql0, connection2)



                SqlCom.Parameters.Add(New SqlParameter("@SubjectandSectionandYear", ListBox2.Items(i)))


            Next



Is This A Good Question/Topic? 0
  • +

Replies To: saving all item in listbox(vb2010) in sql2005 database

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: saving all item in listbox(vb2010) in sql2005 database

Posted 18 January 2012 - 05:23 AM

Where did you execute your query? outside the loop? It should be inside the loop so every parameter added is executed and saved to the db
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1