VB operation Access Instance exercises--ATM Teller machine code snippet

Source: Internet
Author: User
====================================
General
====================================
Connect to the database (concatenate the database string and call the function):

Dim Con As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data source= atm.mdb"        Dim connconnection As Oledb.oledbconnection = New oledb.oledbconnection        connconnection.connectionstring = Con        connconnection.open ()

Verify user name password (that is, take the user name password entered on the interface to the database to match, if you can find the pass):

Private Function Userisvalid () as Boolean        ' Connect database        Dim Con as String = ' Provider=Microsoft.Jet.OLEDB.4.0;Data Source= atm.mdb "        Dim connconnection as Oledb.oledbconnection = New oledb.oledbconnection        connconnection.connectionstring = Con        connconnection.open ()
    ' Verify that the user name password exists        Dim strSQL as String = "SELECT * from accountinfo where Accountno = '" &       Trim (TextBox1.Text) & "' and Password = '" & Trim (TextBox2.Text) & "'"        Dim conncommand as Oledb.oledbcommand = New oledb.oledb Command (strSQL, connconnection)        Dim myreader as Oledb.oledbdatareader = Conncommand.executereader        ' If there is data        if Myreader.hasrows then            myreader.read () ' reads a row of data into reader            If Trim (TextBox1.Text) = myreader (1) and Trim ( TextBox2.Text) = myreader (2) then                connconnection.close ()                Return True            Else                connconnection.close ( Return                false            End If        connconnection.close ()        ' No data directly returns error return        false    end Function

Exit (in fact, all open windows are hidden, the login window will be displayed on it):

For each F as Form in Application.openforms            f.hide ()            frmlogin.show ()        Next

====================================
Customer
====================================
Withdrawal:

' Connect database        Dim Con As String = ' Provider=Microsoft.Jet.OLEDB.4.0;Data source= atm.mdb '        Dim connconnection As Oledb.oledbconnection = New oledb.oledbconnection        connconnection.connectionstring = Con        connconnection.open  ()        ' Modify amount (save money)        Dim sql as String = "Update accountinfo set Balance = Balance +" + TextBox1.Text + "where Accountno = ' "+ frmLogin.TextBox1.Text +" ' "        Dim cmd as Oledb.oledbcommand = New oledb.oledbcommand (sql, connconnection)        C Md. ExecuteNonQuery ()        ' record operation log        sql = ' INSERT INTO accountact (Accountno,lastopt,amount) VALUES (' "& Trim ( FrmLogin.TextBox1.Text) & "', '" & Trim (DateTime.Now.ToString ()) & "',        " & CType (TextBox1.Text, Double) & ")"        Dim cmd2 as Oledb.oledbcommand = New oledb.oledbcommand (sql, connconnection)        cmd2. ExecuteNonQuery ()        connconnection.close ()

Deposit:

' Connect database        Dim Con As String = ' Provider=Microsoft.Jet.OLEDB.4.0;Data source= atm.mdb '        Dim connconnection As Oledb.oledbconnection = New oledb.oledbconnection        connconnection.connectionstring = Con        connconnection.open  ()        ' Modify amount (take money)        Dim sql as String = "Update accountinfo set Balance = Balance-" + TextBox2.Text + "where Accountno = ' "+ frmLogin.TextBox1.Text +" ' "        Dim cmd as Oledb.oledbcommand = New oledb.oledbcommand (sql, connconnection)        C Md. ExecuteNonQuery ()        ' record operation log        sql = ' INSERT INTO accountact (Accountno,lastopt,amount) VALUES (' "& Trim ( FrmLogin.TextBox1.Text) & "', '" & Trim (DateTime.Now.ToString ()) & "',        " & CType (TextBox1.Text, Integer) & ")"        cmd = New oledb.oledbcommand (sql, connconnection)        cmd. ExecuteNonQuery ()        connconnection.close ()

Enquiry Account:

' Connect database        Dim Con As String = ' Provider=Microsoft.Jet.OLEDB.4.0;Data source= atm.mdb '        Dim connconnection As Oledb.oledbconnection = New oledb.oledbconnection        connconnection.connectionstring = Con        connconnection.open ()        Dim sql As String = "Select Balance from accountinfo where Accountno = '" + frmLogin.TextBox1.Text + "'"        Dim cm D as Oledb.oledbcommand = New oledb.oledbcommand (sql, connconnection)        Dim myreader as Oledb.oledbdatareader = cmd. ExecuteReader        If Myreader.hasrows then            myreader.read ()            Label1.Text = myreader (0)        Else            MessageBox.Show ("Account information not found")        End If        connconnection.close ()

===================================
Administrator
==================================
Logging the Operation log:

sql = "INSERT into Accountact (Accountno,lastopt,amount) VALUES ('" & Trim (FrmLogin.TextBox1.Text) & "', '" & T Rim (DateTime.Now.ToString ()) & "'," & CType (TextBox1.Text, Integer) & ")"        cmd = New Oledb.oledbcommand (s QL, connconnection)        cmd. ExecuteNonQuery ()        connconnection.close ()

To view all operation logs:

' Connect database        Dim Con As String = ' Provider=Microsoft.Jet.OLEDB.4.0;Data source= atm.mdb '        Dim connconnection As Oledb.oledbconnection = New oledb.oledbconnection        connconnection.connectionstring = Con        connconnection.open ()        ' Take the data of the query out and put it into data set        Dim strSQL as String = "SELECT * from Accountact"        Dim mydataset as DataSet = New DataS ET ()        Dim myadapter as Oledb.oledbdataadapter = New oledb.oledbdataadapter (strSQL, connconnection)        Myadapter.fill (myDataSet, "Accountact")        connconnection.close ()        ' pulls data out of the dataset to display on the control ()        Datagridview1.datasource = mydataset.tables (0)        Datagridview1.autosizecolumnsmode = Datagridviewautosizecolumnsmode.allcells

View all user accounts

' Connect database        Dim Con As String = ' Provider=Microsoft.Jet.OLEDB.4.0;Data source= atm.mdb '        Dim connconnection As Oledb.oledbconnection = New oledb.oledbconnection        connconnection.connectionstring = Con        connconnection.open ()        ' Take the data from the query and put it into data set        Dim strSQL As String = "SELECT * from AccountInfo"        Dim mydataset as DataSet = New data Set ()        Dim myadapter as Oledb.oledbdataadapter = New oledb.oledbdataadapter (strSQL, connconnection)        Myadapter.fill (myDataSet, "AccountInfo")        connconnection.close ()        ' pulls data out of the dataset to display on the control ()        Datagridview1.datasource = mydataset.tables (0)        Datagridview1.autosizecolumnsmode = Datagridviewautosizecolumnsmode.allcells

The above is the VB Operation Access instance exercises--ATM Teller machine code section content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.