For example i have the following fields in the database

name, student number, course

then i have multiple data in the database e.g. 25rows = 25 students

when i try to edit them, you need to first click the row in the datagrid that you want to edit

then ive used this code to send the information of the student from the datagrid into multiple textbox


txtname.Text = Adodc1.Recordset.Fields.Item("dbname").Value
txtstudentnumber.Text = Adodc1.Recordset.Fields.Item("dbstudentnumber").Value
txtcourse.Text = Adodc1.Recordset.Fields.Item("dbcourse").Value
THIS IS THE CODE IVE USED TO PASS THE DATA IN THE TEXTBOX IF YOU CLICK A SPECIFIC ROW IN THE DATAGRID


adodc1.recordset!dbname = txtname.text
adodc1.recordset!studentnumber = txtstudentnumber.text
adodc1.recordset!dbcourse = txtcourse.text
Adodc1.Recordset.Update
THIS IS MY CODE IN UPDATING THE SPECIFIC ROW IN DATABASE BUT IT ONLY REPLACES THE FIRST ROW OF INFORMATION IN MY DATABASE, EVEN IVE CLICKED DIFFERENT ROW e.g. 12TH ROW IN THE DATABASE IT REPLACES THE FIRST ROW IN THE DATABASE


but after ive click the save button it replaces/ edit the first row in the database and not the specific row that has been clicked in the datagrid...

i dont have idea what is the exact code for updating the specific row, because i used the code above to insert a new information in the database using adodc1.recordset.addnew

I need help in creating/ having a code that if you clicked a specific row in the datagrid it will pass the information in the textbox, then after you clicked a button to update it it will edit the clicked row in the datagrid/ database...

Also I need help in deleting specific row in the datagrid. database

thanks in advance :)

You need to write code to move to the next row in the database:

Adodc1.Recordset.MoveNext

or

Adodc1.Recordset.MovePrev

depending on what you're doing.

If you want to get fancy, you can seek a particular row:

Adodc1.Recordset.seek ...

You will have to find out which row was selected first and then update the recordset. Use something like -

Text1.Text = Datagrid1.TextMatrix(Datagrid1.Row, 1)
Text2.Text = Datagrid1.TextMatrix(Datagrid1.Row, 2)
Text3.Text = Datagrid1.TextMatrix(Datagrid1.Row, 3)
'and so on...

:)

ok ill check it out in my system after the exam, thanks ill automatically click answered if it is the solution in my problem

It was a pleasure. Good luck for your exams.:)

Apparently, the datagrid control changes rows on its own when you click on the datagrid or when you are using the ADODC. But you should not
use the click event. Rather, use the RowColChange event and use the bookmark property to set the row.

Private Sub DataGrid1_RowColChange(LastRow as Variant, ByVal LastCol as Integer)
     text1 = DataGrid1.Columns("ProductID").CellValue(DataGrid1.Bookmark)
End Sub

' If you'll do the above, then updating the data should be fairly simple:

Private Sub cmdUpdate_Click()
     DataGrid1.Columns("UnitPrice") = Text1
End Sub

hi! i've been using VB6, Access, and ADO, and i've been having the same problem when a certain user logs-in and changes his account. what happens also is that the account of the user in the first row of the databse is the one that's being changed. May i ask if you were able to solve this problem?

@csantiago, The answer is contained within the above posts.

Firstly you need to open your own thread with your question if it is not related to this or it is not working for you. We will then supply a solution from there.:)

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.