1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Vb database error

Discussion in 'Visual Basic ( VB )' started by Sanchita Chakrabarty, Jul 30, 2004.

  1. Sanchita Chakrabarty

    Sanchita Chakrabarty New Member

    Joined:
    Jul 30, 2004
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    In relational database,eg: bank management i want to knw how to update the table in the deposit section, after a run time error is detected,if the account no: does not exist.In my case the control stops in that particular line. It does not go to the next line.So if u can please help me.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Use Ado object and not Ado control for better results. This just gives the hints as how to do it.

    This code can give errors related to database and so Use more standard code. This is just an illustration of concept as to how to do it.

    Code:
    'Put 2 textbox, 1 command button and one ado controland connect to database
    which has table name account with 2 fields accno and name where accno is primary 
    key field.
     
    Private Sub Command1_Click()
    On Error GoTo ErrorHandler
    If flag = False Then
    'Change command button caption
    	Command1.Caption = "Save"
    Else
    'Insert the data and check if error occurs on primary key
    	On Error GoTo DatabaseErrorHandler
    	'Database error
    	Adodc1.RecordSource = "Insert into account values(" + Text1.Text + ",'" + Text2.Text + "');"
    	Adodc1.Refresh
    	On Error GoTo ErrorHandler
    	Command1.Caption = "Add"
    End If
    flag = Not flag
    Exit Sub
    DatabaseErrorHandler:
    'Change the value and insert
    	Text1.Text = "3"
    	Text2.Text = "New Name"
    	Adodc1.RecordSource = "Insert into account values(" + Text1.Text + ",'" + Text2.Text + "');"
    	Adodc1.Refresh
    ErrorHandler:
    	MsgBox Err.Description, vbCritical + vbOKOnly
    End Sub
    
     
    Last edited: Jul 30, 2004

Share This Page