Is there possiblity to send, 5 data(5rows) at one time to the sql database in vb.net2008

Recommended Answers

All 2 Replies

Yes. Just adjust your insert query.

... VALUES (1, 'a'), (2, 'b'), (3, 'c')

Let me know whereto adjust.................

 Dim comd As SqlCommand = myConnection.CreateCommand()
        Try
            myConnection = New SqlConnection(connectionstring)
            myConnection.Open()
            comd.Connection = myConnection
            comd.CommandText = "Insert into NEW1([Fruits] ,[Countries]) values( @Fruits   ,@Countries)"

            'Adding Parameters
            comd.Parameters.Add("@Fruits", SqlDbType.VarChar, 250)
            comd.Parameters.Add("@Countries", SqlDbType.NVarChar, 250)
            'comd.Parameters.Add("@Qty", SqlDbType.VarChar, 50)
            'comd.Parameters.Add("@Rte", SqlDbType.VarChar, 50)
            'comd.Parameters.Add("@TotalAmt", SqlDbType.VarChar, 50)

            comd.Prepare()
            'Data Inserted

            For Each row As DataGridViewRow In DataGridView1.Rows
                If Not row.IsNewRow Then
                    comd.Parameters("@Fruits").Value = row.Cells(0).Value.ToString
                    comd.Parameters("@Countries").Value = row.Cells(1).Value.ToString
                    '    comd.Parameters("@Qty").Value = row.Cells(2).ToString
                    '    comd.Parameters("@Rte").Value = row.Cells(3).ToString
                    '    comd.Parameters("@TotalAmt").Value = row.Cells(4).ToString
                End If
            Next
            comd.ExecuteNonQuery()
            MessageBox.Show("Data Inserted")

        Catch ex As Exception
            MessageBox.Show("Error :" & ex.ToString())
        Finally
            myConnection.Close()
        End Try
        'Else
        'MessageBox.Show("Enter PoNumber")
        'End If
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.