
addnew and update methods ?
Hi,
I'm using VB 4.0 with ODBC driver and SQL Server 6.5.
My data controls are using the following Connect string:
ODBC;DATABASE=ICIIS;UID=ICIISUser;PWD=iciisuser;DSN=dsVB1;
I'm trying to use a cmdAdd button to add a new record to the CustInfo
table in the DB. Before I update the change, I need to read the max ID
using for the CustInfo table from another data control. I use the
following codes:
Private Sub cmdAdd_Click()
datMaxID.Recordset.Edit
datMaxID.Recordset.Fields("CustSuppID").Value = datMaxID.Recordset.Fields("CustSuppID").Value + 1
datMaxID.Recordset.Update
datCustInfo.Recordset.AddNew
End Sub
And I use another button cmdSave to save the change.
Private Sub cmdSave_Click()
txtCustInfoID.Text = datMaxID.Recordset.Fields("CustSuppID").Value
datCustInfo.Recordset.Update
End Sub
When I tried to run these, there's no prob when the table is empty.
But if there're some rows in the table, it will get run-time error
of 3020 "Update or CancelUpdate without AddNew or Edit."
at the Update method.
Am I missing anything??
Thanks in advance.
--
___ _
| _ | / _` | ' \ Future Solutions Laboratory Limited (852)2319-2488
|_| |_|_\__,_|_||_| Rm 317, HKITC, Tat Chee Avenue, Kowloon, Hong Kong