[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2164
  • Last Modified:

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

0
cyyam
Asked:
cyyam
1 Solution
 
tat83Commented:
hi
ur second problem is similiar to this question
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Databases/Q_20554434.html
so take a look at it
it will solve ur second question
0
 
cerebralpcCommented:
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

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Databases/Q_20554369.html
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now