===================================
범용
==== ================================
데이터베이스에 연결합니다(연결 데이터베이스 문자열을 연결하고 함수를 호출하면 됩니다). ):
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()
사용자 이름과 비밀번호를 확인하세요(즉, 인터페이스에 입력된 사용자 이름과 비밀번호를 데이터베이스에서 일치시키세요. 찾을 수 있으면 통과하세요):
Private Function UserIsValid() As Boolean '连接数据库 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 strSql As String = "select * from AccountInfo where AccountNo = '" & _ Trim(TextBox1.Text) & "' and Password = '" & Trim(TextBox2.Text) & "'" Dim connCommand As OleDb.OleDbCommand = New OleDb.OleDbCommand(strSql, connConnection) Dim myReader As OleDb.OleDbDataReader = connCommand.ExecuteReader '如果有数据 If myReader.HasRows Then myReader.Read() '读一行数据到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 End If connConnection.Close() '没数据直接返回错误 Return False End Function
=================== == ==============
고객
=========================== ===== =======
출금:
For Each f As Form In Application.OpenForms f.Hide() frmLogin.Show() Next
입금:
'连接数据库 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 = "update AccountInfo set Balance = Balance + " + TextBox1.Text + " where AccountNo = '" + frmLogin.TextBox1.Text + "'" Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(sql, connConnection) cmd.ExecuteNonQuery() '记录操作日志 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()
계좌조회:
'连接数据库 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 = "update AccountInfo set Balance = Balance - " + TextBox2.Text + " where AccountNo = '" + frmLogin.TextBox1.Text + "'" Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(sql, connConnection) cmd.ExecuteNonQuery() '记录操作日志 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()
=== ===============================
관리자
====== ==== ========================
작업 로그 기록:
'连接数据库 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 cmd 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("未找到账户信息") End If connConnection.Close()
모든 작업 로그 보기:
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()
모든 사용자 계정 보기
'连接数据库 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() '把查询的数据取出来放到data set Dim strSql As String = "select * from AccountAct" Dim myDataSet As DataSet = New DataSet() Dim myAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(strSql, connConnection) myAdapter.Fill(myDataSet, "AccountAct") connConnection.Close() '把数据从dataset中取出来显示在控件上() DataGridView1.DataSource = myDataSet.Tables(0) DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
위는 VB ACCESS 동작 예제 운동-ATM 현금인출기 코드 부분의 내용입니다. PHP 중국어 홈페이지(www.php.cn)를 주목해주세요!