1,105,594 Community Members

Inserting data through Data gridview

Member Avatar
Dili1234
Junior Poster
169 posts since Aug 2012
Reputation Points: -2 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 3 [?]
 
0
 

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

Member Avatar
pritaeas
mod_pritaeas
11,315 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 156 [?]
Moderator
Featured
Sponsor
 
0
 

Yes. Just adjust your insert query.

... VALUES (1, 'a'), (2, 'b'), (3, 'c')
Member Avatar
Dili1234
Junior Poster
169 posts since Aug 2012
Reputation Points: -2 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 3 [?]
 
0
 

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
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article