我正在做我的最终项目,通过VB .net和SQL DATABASE创建一个银行ATM系统 这是我的问题: 我想仅在Datagridview中显示帐户余额,其中USER_LOGIN = txt_id.Text 如果我是用户1,我想只显示用户1帐户余额。 /如果我是用户2,我想如何只用户2账户余额。
数据库信息 - 数据库名称 - USERLOGIN || 表 - USER_LOGIN,USER_PASSWORD,USER_PIN,USER_BALANCE
这是我的表格信息: 登录表单 - txt_id.Text,txt_pw.Text || PIN表格 - txt_pin.Text || 余额表 - Datagridview与数据库和完成数据集的连接 抱歉我的英语不好
这是我的代码: (登录表格)
Imports System.Data.SqlClient
Public Class Login
Dim Attempts As Integer = 0
Private Sub btn_next_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_next1.Click
Dim txtid As String
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim rd As SqlDataReader
txtid = Me.txt_id.Text
con.ConnectionString = "Data Source=HOME-PC; Initial Catalog=csbanking; Integrated Security= true "
cmd.Connection = con
con.Open()
cmd.CommandText = "select USER_LOGIN, USER_PASSWORD from USERLOGIN where USER_LOGIN = '" & txt_id.Text & "' and USER_PASSWORD = '" & msktxt_pw.Text & "'"
rd = cmd.ExecuteReader
If rd.HasRows Then
Security.Show()
txt_id.Text = ""
msktxt_pw.Text = ""
Me.Hide()
Else
MessageBox.Show("Invalid ID or Password")
Attempts += 1
txt_id.Text = ""
msktxt_pw.Text = ""
End If
If Attempts = 3 Then
MessageBox.Show("You have reached limit of login, System Restarting...")
_1stpage.Show()
Me.Close()
End If
End Sub
(保密表格)
Imports System.Data.SqlClient
Public Class Security
Dim Attempts As Integer = 0
Private Sub btn_next2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_next2.Click
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim rd As SqlDataReader
con.ConnectionString = "Data Source=HOME-PC; Initial Catalog=csbanking; Integrated Security= true "
cmd.Connection = con
con.Open()
cmd.CommandText = "select USER_PIN from USERLOGIN where USER_PIN = '" & msktxt_pin.Text & "'"
rd = cmd.ExecuteReader
If rd.HasRows Then
Menu1.Show()
Me.Hide()
Else
MessageBox.Show("Invalid Security PIN")
Attempts += 1
msktxt_pin.Text = ""
End If
If Attempts = 3 Then
MessageBox.Show("You have reached the limit numbers of login, System Restarting...")
_1stpage.Show()
Me.Close()
End If
End Sub
(菜单表格)
Public Class Menu1
Inherits System.Windows.Forms.Form
Private Sub btn_balance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_balance.Click
Dim nex2 As Balance
nex2 = New Balance
nex2.Show()
Me.Hide()
End Sub
End Class
(平衡表)
Public Class Balance
Private Sub Balance_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OleDbDataAdapter1.Fill(Csbanking1)
End Sub