Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello friends,
I want to upload the data Inserted into DataGridView to my sql server table needed help...
Posted

You should bind your datagrid to your database table (or vice versa), so whenever you add, update or delete a data in your datagrid, it will also reflect in your database table.
 
Share this answer
 
VB
Private Sub inserttoDatagridview()
        con.Open()
        For Each rw As DataGridViewRow In DataGridView1.Rows
            cmd = New SqlCommand("insert into tblEmp (empid,empname,empdesg,dob) values (" & rw.Cells(0).Value & ",'" & rw.Cells(1).Value & "','" & rw.Cells(2).Value & "','" & CDate(rw.Cells(3).Value.ToString()) & "') ", con)
            cmd.ExecuteNonQuery()
        Next
        con.Close()
    End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900