How do I insert multiple record in a loop with ado.net ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have to insert all Items of a listbox to a table ? How can I do that ? The code bellow always add the same first item to the table. must be another way to do this. Thank'

Dim Conn As String = "Provider=Microsoft.Jet.OLEDB......
Dim strSQL = "Insert into Documents (IdFiche, PathDoc) values (@IdFiche, @PathDoc);
Dim Cmd As New OleDbCommand(strSQL, Conn
dim zItem as listIte

for each zItem in Listbox1.Item
With Cmd.Parameter
.Add(New OleDbParameter("@IdFiche", IdCle)
.Add(New OleDbParameter("@PathDoc", zItem.Text)
End Wit
Cmd.ExecuteNonQuery(
next zItem
 
You should add the parameter once (outside the loop), and just change their
values inside the loop.

Jeff said:
I have to insert all Items of a listbox to a table ? How can I do that ?
The code bellow always add the same first item to the table. must be another
way to do this. Thank's
 
Back
Top