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

Discussion in 'ASP .Net' started by =?Utf-8?B?SmVmZg==?=, Apr 14, 2004.

  1. 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
    =?Utf-8?B?SmVmZg==?=, Apr 14, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?SmVmZg==?=

    Marina Guest

    You should add the parameter once (outside the loop), and just change their
    values inside the loop.

    "Jeff" <> wrote in message
    news:...
    > 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
    >
    > 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 listItem
    >
    > for each zItem in Listbox1.Items
    > With Cmd.Parameters
    > .Add(New OleDbParameter("@IdFiche", IdCle))
    > .Add(New OleDbParameter("@PathDoc", zItem.Text))
    > End With
    > Cmd.ExecuteNonQuery()
    > next zItem
    Marina, Apr 14, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmVmZg==?=

    Insert multiple record into table using ado.net ?

    =?Utf-8?B?SmVmZg==?=, Apr 14, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    985
    =?Utf-8?B?SmVmZg==?=
    Apr 14, 2004
  2. nita
    Replies:
    1
    Views:
    864
    Saravana
    Nov 20, 2004
  3. Frits van Soldt

    How to insert a new record in detailsview when there are no record

    Frits van Soldt, Nov 16, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    733
    Frits van Soldt
    Nov 17, 2005
  4. Guest
    Replies:
    1
    Views:
    253
    Alex G
    Jan 9, 2004
  5. Isaac Won
    Replies:
    9
    Views:
    364
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page