Using VB6
I am saving the user the entry in the database.
Code.
rst.Open "SELECT * FROM ShiftMaster WHERE Shift_Code = '" & Trim(txtCode.Text) & "'", adoPunching, adOpenDynamic, adLockBatchOptimistic
If (rst.BOF And rst.EOF) Then
rst.AddNew
End If
rst!Shift_Code = "" & txtCode.Text
rst!Shift_Name = "" & txtName.Text
rst!Start_Time = "" & Format(dtpFrom.Value, "HH:mm")
rst!End_Time = "" & Format(dtpTo.Value, "HH:mm")
rst.UpdateBatch
rst.Requery
rst.Close
MsgBox "Data successfully saved.", vbInformation
lvdvendor
The above code is working for saving, but if the user enter the same txtcode means it should modify the records, it should add new rows.
For Example
ID Value
001 200
If the user enter the same id in the textbox like 001 and user changed the value like 500 means it should chand only the value, It should add one more row with same id.
How to do this.
Need VB6 Code Help
How do you know which record you are poining to after doing the query? The answer is that you don’t so you need to move to the first record:
One point to note though is that you may return more than one record when you do your query so in this way it will only update the first one it finds. You way want to consider using
TOP 1 *so ensure you only retrieve 1 or 0 records.