I have form that contain a datagrid I want that,
When user selected any row of the datagrid and click's to the edit button
the data of the datagrid will opens in a new form and user can edit it and save.
sorry but i didnt get logic because Im entry level programmer.
How do i write a code on my '
sql server 2010 and vb2008
You really can just Google search "SQL SELECT and UPDATE" queries, however:
To select it, you need to use a query to select all of the information associated to that unique ID (Which you should have?).
Then, load it into a
DataTable. Each control will be assigned it's value using the relevant
Then an update query will be run when you press Save/Update to update it.
Dim Dt As New DataTable Using Da = New OleDbDataAdapter("SELECT * FROM Your_Table WHERE uniqueID=?", connectionstring) Da.SelectCommand.Parameters.Add("@ID", OleDbType.Integer).Value = IDvariable Da.Fill(Dt) End Using
Then you need to use the
DataAdapter to fill in the form controls, for example:
txtFirstName.Text = Dt.Rows(0).Item("firstName")
Try Dim Dc As New OleDbCommand Dc.Connection = connectionstring Dc = New OleDb.OleDbCommand("UPDATE Your_Table SET column_1 = ?, column2 = ? WHERE uniqueID=?", connectionstring) Dc.Parameters.Add("@column1", OleDbType.DataType).Value = control1.Text Dc.Parameters.Add("@column2", OleDbType.DataType).Value = control2.Text Dc.Parameters.Add("@uniqueID", OleDbType.Integer).Value = uniqueID Dc.ExecuteNonQuery() MsgBox("Edit Successful") Catch ex As Exception MsgBox("Failed to update data, refer to error log") End Try