Greetings, i'm having a problem on inserting all my items from listview to my database using stored procedure. heres my code.

Dim lvItem As ListViewItem
       For Each lvItem In ListView1.Items


                With dbComm
                    .AddParameter("@details", lvItem.Text, SqlDbType.VarChar)
                    .ExecuteStoredProcedure("insertRecord")

                    If .Success = False Then
                        MsgBox("Record failed to save.")
                    Else
                        MsgBox("Record Saved.")
                    End If
                End 

Here's my code in stored proc

            INSERT INTO tblRecord (details)
            VALUES (@details)

Recommended Answers

All 3 Replies

See this example (con is the connection object)

    Dim cmd As New SqlCommand("", con)
    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = "InsertRecord"
    cmd.Parameters.Add("@Details", SqlDbType.VarChar)

    con.Open()

    cmd.Parameters("@Details").Value = "Sample details 1"
    cmd.ExecuteNonQuery()
    cmd.Parameters("@Details").Value = "Sample details 2"
    cmd.ExecuteNonQuery()
    cmd.Parameters("@Details").Value = "Sample details 3"
    cmd.ExecuteNonQuery()

    con.Close()

Just replace the centre block (between con.Open and con.Close) with your loop.

Thank you sir. it gave me an idea :D. Thanks!

hello i want to use microsoft access with using vb tell me how can i add data to access and see data from vb

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.