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.
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Following links should help you.
http://www.codeproject.com/KB/database/relationaladonet.aspx
http://www.akadia.com/services/dotnet_update_form.html
http://fog.ccsf.cc.ca.us/~cpersiko/cs112d/NotesDataAdapterPart2.html
http://www.daniweb.com/forums/thread80953.html
http://bytes.com/forum/thread362652.html
http://www.developerfusion.com/article/4278/using-adonet-with-sql-server/4/
http://www.codeproject.com/KB/database/relationaladonet.aspx
http://www.akadia.com/services/dotnet_update_form.html
http://fog.ccsf.cc.ca.us/~cpersiko/cs112d/NotesDataAdapterPart2.html
http://www.daniweb.com/forums/thread80953.html
http://bytes.com/forum/thread362652.html
http://www.developerfusion.com/article/4278/using-adonet-with-sql-server/4/
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!!!
ASKER