sql database update


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: sql database update

  1. #1
    Join Date
    Mar 2005
    Location
    batam
    Posts
    14

    sql database update

    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]
    Last edited by ksuwanto8ksd; 06-12-2005 at 05:25 AM.

  2. #2
    Join Date
    Jan 2004
    Location
    Alexandria, VA
    Posts
    392
    I don't see any obvious programming holes. Have you tried stepping through the program in the debugger to see where the problem might be?
    Bob Rouse
    Dimension Data

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center