通用
====================================
连接数据库(拼接连接数据库字符串,调用函数即可):
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,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,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
查看所有用户账号
'连接数据库 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 AccountInfo" Dim myDataSet As DataSet = New DataSet() Dim myAdapter As oleDb.oleDbDataAdapter = New oleDb.oleDbDataAdapter(strsql,"AccountInfo") connConnection.Close() '把数据从dataset中取出来显示在控件上() DataGrIDVIEw1.DataSource = myDataSet.tables(0) DataGrIDVIEw1.autoSizeColumnsMode = DataGrIDVIEwautoSizeColumnsMode.AllCells总结
以上是内存溢出为你收集整理的VB *** 作ACCESS 实例 练习题--ATM取款机 代码段全部内容,希望文章能够帮你解决VB *** 作ACCESS 实例 练习题--ATM取款机 代码段所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)