Link to home
Start Free TrialLog in
Avatar of mittalmunish80
mittalmunish80

asked on

how can I Add new Rows to Datagridview dynamically and these new rows should be updated in database table automatically just like in datagrid in VB6

I am new to VB 2005. I have created a new form in VB.NET 2005 and placed  datagridview on the form.
its property AllowUserToAddRows is set to true and placed a button on form. It shows data on the grid properly and allows to add rows but these rows are not reflected in database table.  how can I Add new Rows to Datagridview dynamically and these new rows should be Added in database table automatically just like in datagrid in VB6. I also want whenever any cell is updated its values should be updated in database table. How can we make some columns editable and others are not.


Imports System.Data.SqlClient
Public Class Form1
    Private LawCon As SqlConnection
    Private LawDa As SqlDataAdapter
    Private LawDs As DataSet
    Private Lawcmd As SqlCommand
 
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        LawCon = New SqlConnection("server=MITTAL;uid=sa;pwd=;database=mys")
        LawDa = New SqlDataAdapter("select * from Law1", LawCon)
        LawDs = New DataSet()
        LawDa.Fill(LawDs, "Laws")       
        DataGridView1.DataSource = LawDs.Tables("Laws")
        DataGridView1.Refresh()
 
 
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mittalmunish80
mittalmunish80

ASKER

Can you tell me through sample code or by updating my code
Is there a way of changing the zone? This is a VB.NET question and VB.NET is among the selected zones but i was awarded points in the Languages zone!!!