Hi
This is the code that I write to update database sql. When user type a
number in text1.text press enter, he will open TABEL1 and check record
from first to last to chech field(0), if exist text2 get value field(1)
and value in field(1) is deduted by 1 and update to the TABEL1
The fact here when runtime, every record in the TABEL1 are deducted when
number exist;text1.text=field(0)
When I use change the connectionstring and connect to Acces tabel, it
run smoothly;only 1 record is updated.
If any one could give an idea of how it would work be greatly appreciated
and thanks a lot
Code:[vbcode] Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Label3.Visible = False On Error GoTo errhandler 'on error resume next Set objConnection = New ADODB.Connection objConnection.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=adodata;Data Source=pc14;" objConnection.CursorLocation = adUseClient objConnection.Open Set objRS = New ADODB.Recordset objRS.Open "SELECT * FROM TABLE1", objConnection, adOpenDynamic, adLockOptimistic objRS.MoveFirst Do While Not objRS.EOF If Text1.Text = objRS.Fields(0) Then Text2.Text = objRS.Fields(1) If Text2.Text <= 1 Then Text1.Text = "" Text2.Text = "" objConnection.Close Label3.Caption = "Sorry! Code expired" Label3.Visible = True Exit Sub Else lngSetTop = SetTopMost(hWnd, False) Timer1.Enabled = True objRS.Fields(1) = objRS.Fields(1) - 1 objRS.Update DisableCtrlAltDelete (True) Form1.Show AdoDao.Visible = False Exit Do End If End If objRS.MoveNext Loop End If errhandler: If Err.Number = 2147467259 Then objConnection.Close AdoDao.Show Label3.Caption = "Server fail" Label3.Visible = True Exit Sub End If End Sub [/vbcode]


Reply With Quote


Bookmarks