Link to home
Start Free TrialLog in
Avatar of raj_ms
raj_ms

asked on

how to update the table with the datagridvalues using ADODB.recordset

I would like to know how do i update the values from the data grid to the database table. after making changes in the datagrid. i would loike to load the datagrid with database table values and after making changes i would like to update the values in the database.
Avatar of Noel_Castillo
Noel_Castillo

Its just a matter of setting some properties in datagrid. like allowupdate. once you make changes to the grid and change the row. the changes will be reflected in the database. AllowAddnew will allow the user to create a new record by filling up the empty row in the bottom. and do on. :)
Avatar of raj_ms

ASKER

NO i am not using ADODC
Avatar of raj_ms

ASKER

What you say is, when we use ADO DC control
Avatar of raj_ms

ASKER

I have enabled the checkbox in the datagrid, even now its not updating becaz i am not using ADO Data control
Avatar of raj_ms

ASKER

i want to use without ADO DC control
did you checked the allowupdate property?
that should work. even in adodb.

datagrid.datasource = rs  'something like this right? after creating recordset

Avatar of raj_ms

ASKER

yes i have checked but what you say is to fill datagrid wiyth rs but i want to update the changes in the datagrid to database table
Avatar of raj_ms

ASKER

i want the vice versa
Avatar of raj_ms

ASKER

Dear Noel_Castillo,
I have done what ever you have told me. but i wish to update the table with the datagrid
Avatar of Ioannis Paraskevopoulos
Add a datagrid control and a button on a form.When the form is loaded try changing the value of a cell and then click update.Then check your original database, and you'll see it is updated.


Dim mycnn As ADODB.Connection
Dim rs As ADODB.Recordset

Private Sub cmdUpdate_Click()
rs.UpdateBatch
End Sub

Private Sub Form_Load()
Set mycnn = New ADODB.Connection
Set rs = New ADODB.Recordset
mycnn.ConnectionString = "Provider=MSDataShape;Data Provider=SQLOLEDB;Server=FIT4;Database=Host;UID=sa;PWD=;"
mycnn.Open
rs.Open "Add your SQL statement here", mycnn, adOpenDynamic, adLockBatchOptimistic

Set DataGrid1.DataSource = rs

End Sub
Avatar of raj_ms

ASKER

No it didnt update
Avatar of raj_ms

ASKER

when i see the table its not updated
it did mine.
Did any error come up?
did you set the connection string correct?
it is strange because the code i gave you works with me.

Have you checked if your database allows updates?

Do you have administrative rights on the pc you're using?


After you press the update button on your form,have hou refreshed your database so to be sure you have the updated values?
Avatar of raj_ms

ASKER


Public Sub loadRates()
   Set lr = New ADODB.Recordset
   lr.CursorLocation = adUseClient
   lr.Open "select * from raj.rates", cn, 3, 2
   Set Form1.DataGrid2.DataSource = lr
   Form1.DataGrid2.Columns(0).Visible = False
End Sub
Public Sub clearRates()
    Set Form1.DataGrid2.DataSource = Nothing
End Sub
Sub changeRates()
lr.updateBatch
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Ioannis Paraskevopoulos
Ioannis Paraskevopoulos
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of raj_ms

ASKER

it produces an error
Row cannot be located for updating. Somevalues may have been changed since it was last read.

Dear
its so simple

Only to set the datagrid allowupdate property to true
and what ever changes you are entering in your gird are automatically update in your database.

You havenothing to do it except only to make chanege the
allowautoupdate propertly to true

Banger
Avatar of raj_ms

ASKER

i have set the allowupdate property to true.......
even now i couldnt update.........
im sorry i have to go last friday before answering ur last query. Im wondering why that doesnt work for you. Are you sure that the table is updatable? Or you have a full access on it? :)
Avatar of raj_ms

ASKER

s indeed i tried it manually