Link to home
Start Free TrialLog in
Avatar of cyyam
cyyam

asked on

DataGrid and Adodc recordset handling

High ,
I have a DataGrid (DataGrid1) connected to a Adodc (Adodc1) as the data source.
And I have some button for manipulating the field (Add, Delete, Update).


' --- Set the DataGrid1 and connect it to Adodc1
DataGrid1.AllowAddNew = True
DataGrid1.AllowDelete = True
DataGrid1.AllowUpdate = True
   
Adodc1.ConnectionString = dlgNewApp1.StrConn
   
Adodc1.RecordSource = "SELECT * FROM " & dlgNewApp1.recTableName
Adodc1.Refresh
   
Set DataGrid1.DataSource = Adodc1
   


' ---  The Delete button ---
Private Sub cmdDelete_Click()
'    Adodc1.Recordset.CancelUpdate
'    Adodc1.Recordset.CancelBatch
If Adodc1.Recordset.EOF Or Adodc1.Recordset.BOF Then
    MsgBox "There is no record!"

ElseIf IsNull(Adodc1.Recordset) Then
    MsgBox "The field is null, cannot be deleted!"
Else
    Adodc1.Recordset.Delete
End If

End Sub

'--- The New button ---
Private Sub cmdNew_Click()
    Adodc1.Recordset.AddNew
End Sub

' --- The Update button ----
Private Sub cmdUpdate_Click()
If Adodc1.Recordset.EOF Or Adodc1.Recordset.BOF Then

Else
    Adodc1.Recordset.Update
End If
End Sub

My problems are :
1. When I press "Add" , two blank rows (I expect just one )are added in the DataGrid, which cause many inconvenience...

2. When I doubly press  "Add" without filling in the blank rows, then error message:
   "Empty row cannot be inserted. Row must have at least one column value set "
I know that 's because my previous row is empty. Is there any setting to solve this? if no, could you tell me how to write code to prevent ...

I hope there will be some easy trick or setting to deal with these little problem ...

Many Thanks!

cyyam

ASKER CERTIFIED SOLUTION
Avatar of tat83
tat83

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 cerebralpc
cerebralpc

cyyam,
No comment has been added lately (141 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to tat83

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

cerebralpc
EE Cleanup Volunteer

https://www.experts-exchange.com/questions/20554369/DataGrid-and-Adodc-recordset-handling.html