|
|
|
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: |
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 ) |
|
|