Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Updating records in DataList and ADO Data Controls

Total Hit ( 3339)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


If you use a DataList control linked to an ADO Data Control and if you want to add a record, you have to create a command button with this code:

Click here to copy the following block
Private Sub cmdAdd_Click()
 On Error GoTo AddErr
 datPrimaryRS.Recordset.AddNew
 txtNew.SetFocus
 Exit Sub
AddErr:
 MsgBox Err.Description
End Sub

You can specify the new item through txtNew textbox. To allow the user to save this record, you have to add an other button, with this code in its Click event:

Click here to copy the following block
Private Sub cmdUpdate_Click()
 On Error GoTo UpdateErr
 datPrimaryRS.Recordset.Update
 datPrimaryRS.Refresh
 Exit Sub
UpdateErr:
 MsgBox Err.Description
End Sub

However, if you execute this example and try to add a new item, you'll notice that even after pressing the cmdUpdate button, the new item won't appear in the DataList. To correct this problem, you have to add a call to Requery method before Refresh. This is the correct code:

Click here to copy the following block
Private Sub cmdUpdate_Click()
 On Error GoTo UpdateErr
 datPrimaryRS.Recordset.Update
 datPrimaryRS.Recordset.Requery
 datPrimaryRS.Refresh
 Exit Sub
UpdateErr:
 MsgBox Err.Description
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.