I was working with VB.NET and SQL Server database. I want to display selected row into the textbox so that I can edit them and update to database. But when I finished my code, it comes out an exception told me the column name is not found. I double checked the column name and confirm I was spelling correct. What is the problem? Here is my code:
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.RowIndex >= 0 Then
Dim row As DataGridViewRow
row = Me.DataGridView1.Rows(e.RowIndex)
TextBox1.Text = row.Cells("StudentID").Value.ToString
TextBox2.Text = row.Cells("StudentName").Value.ToString
TextBox3.Text = row.Cells("HomeAddress").Value.ToString
TextBox4.Text = row.Cells("ContactNumber").Value.ToString
TextBox5.Text = row.Cells("SubjectCode").Value.ToString
TextBox6.Text = row.Cells("SubjectName").Value.ToString
TextBox7.Text = row.Cells("ParentName").Value.ToString
TextBox8.Text = row.Cells("ParentContact").Value.ToString
End If
End Sub
Here is my database:
Also I want to ask how can I update/refresh my database by using a button? I look through online but nothing effective, I want to refresh the database after I add/edit/delete a data.
Thank you very much.