Hello.
I think You know who to fill a DatagridView??
You will get the selected rows with an Eventhandler:
Private Sub DataGridView1_CellContentDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentDoubleClick, DataGridView1.CellClick, DataGridView1.CellContentClick
...
Dim Row As Integer = e.RowIndex()
dim content as string = ds.Tables(0).Rows(Row).Item(0)
End Sub
So you can get every content form you DataGridView..
Problem Number 2:
Change Cells in Datagridview and write them back into DB:
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
Dim sqlConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection("YOUR SQL CONNECTION STRING")
Dim sqlcmd As SqlCommand = New SqlCommand("YOUR SQL SEARCH = THE SAME AS FOR THE DATAGRID")
sqlConnection.Open()
Dim da As New SqlDataAdapter(sqlcmd)
Dim dsDb As New DataSet
da.Fill(dsDb)
Dim cb As New SqlClient.SqlCommandBuilder(da)
da.InsertCommand = cb.GetInsertCommand
da.DeleteCommand = cb.GetDeleteCommand
da.UpdateCommand = cb.GetUpdateCommand
'DA=Your New DataAdapter and dsDB = orginal Dataset form DB
'ds = your Old DataSet which is connected to the DatagridView
Try
da.Update(ds.Tables(0))
Catch ex As Exception
MessageBox.Show(Convert.ToString(ex))
End Try
sqlConnection.Close()
'REfresh Datagrid is an Method form my Programm.. I can recommend to refresh the datagrid now with the content form your database - so you can check if the command was succesfull
refreshDatagrid()
End Sub
Oh sry i Did't wrote your question. If you want to delete the selected row.. then the da.DeleteCommand = cb.GetDeleteCommand should be enough ;)
Best Regards,
Z