Question how to update records in the database using datagridview and textboxes

jec191

New member
Joined
May 16, 2012
Messages
2
Programming Experience
Beginner
im using sql server 2005 as db and vb.net 2008 as my Prog. Lang..

my database is already connected to my vb.net app. can retrieve records from data base to my datagridview
and once i clicked a cell in data grid view the textboxes can get the values of the selected cells by the use of
this code:

Private Sub dg_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dg.CellClick
txtContactid.Text = Me.dg.SelectedCells(0).Value
txtFName.Text = Me.dg.SelectedCells(1).Value
txtLastname.Text = Me.dg.SelectedCells(2).Value
txtEmail.Text = Me.dg.SelectedCells(3).Value
txtTelnum.Text = Me.dg.SelectedCells(4).Value
End Sub

im stucked there and I don't know how to update selected cell by the use of the textboxes

thats all thanks
thanks
 
You don't need any code at all. Simply bind the data to the grid and the TextBoxes and it will all happen automatically, e.g.
myBindingSource.DataSource = myDataTable
myDataGridView.DataSource = myBindingSource
myTextBox.DataBindings.Add("Text", myBindingSource, "ColumnName")
You can bind multiple TextBoxes and other controls to multiple columns.
 
Back
Top