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.
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. :)
ASKER
NO i am not using ADODC
ASKER
What you say is, when we use ADO DC control
ASKER
I have enabled the checkbox in the datagrid, even now its not updating becaz i am not using ADO Data control
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
datagrid.datasource = rs 'something like this right? after creating recordset
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
ASKER
i want the vice versa
ASKER
Dear Noel_Castillo,
I have done what ever you have told me. but i wish to update the table with the datagrid
I have done what ever you have told me. but i wish to update the table with the datagrid
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=F IT4;Databa se=Host;UI D=sa;PWD=; "
mycnn.Open
rs.Open "Add your SQL statement here", mycnn, adOpenDynamic, adLockBatchOptimistic
Set DataGrid1.DataSource = rs
End Sub
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
mycnn.Open
rs.Open "Add your SQL statement here", mycnn, adOpenDynamic, adLockBatchOptimistic
Set DataGrid1.DataSource = rs
End Sub
ASKER
No it didnt update
ASKER
when i see the table its not updated
it did mine.
Did any error come up?
did you set the connection string correct?
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?
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?
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
Form1.DataGrid2.Columns(0)
End Sub
Public Sub clearRates()
Set Form1.DataGrid2.DataSource
End Sub
Sub changeRates()
lr.updateBatch
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it produces an error
Row cannot be located for updating. Somevalues may have been changed since it was last read.
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
ASKER
i have set the allowupdate property to true.......
even now i couldnt update.........
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? :)
ASKER
s indeed i tried it manually