I have a basic program that access a local Access database, reads data from it into a datagrid, and then allows me to manipulate it by using textboxes. I can add, delete, and search for records. I want to remove the textboxes from the equation completely. Is there any way I can access the data in the datagrid through code so I can use it in SQL statements?

i.e. DataGrid.SelectedRow.Column(3).Value

initial condition

Dim i As Integer
i = dgUser.CurrentRowIndex()

i.e : (this following code will select user where id user = value of first column from selected datagrid). Of course in datagrid click event :

Private Sub dgPendidikan_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgPendidikan.Click
...
cmdUser.CommandText = "SELECT * FROM Users where IdUser ='" & Trim(dgUser.Item(i, 0)) & "'"
....
end sub
commented: Great +1

Thank you so much! I am teaching myself databases, and was stuck on this for days. I thought I tried everything, but I guess not. Thanks!

you're Welcome :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.