VB.NET-从Access数据库中的字段中获取值
我的游戏根据登录的用户将分数保存到数据库字段中。如何从字段中检索分数值并将其输出到文本框?登录的用户将显示在文本框中。下面是允许用户登录的代码。我需要在frmGame.Show之前检索分数值。 谢谢你的帮助VB.NET-从Access数据库中的字段中获取值,vb.net,ms-access,Vb.net,Ms Access,我的游戏根据登录的用户将分数保存到数据库字段中。如何从字段中检索分数值并将其输出到文本框?登录的用户将显示在文本框中。下面是允许用户登录的代码。我需要在frmGame.Show之前检索分数值。 谢谢你的帮助 你的问题不清楚。分数值存储在哪里?你想在哪里展示这种价值?什么不适合你?您收到了什么错误消息?我需要从tbl_用户那里检索分数值,其中用户名为txtUser.text Private Sub OK_Click(ByVal sender As System.Object, ByVal e As
你的问题不清楚。分数值存储在哪里?你想在哪里展示这种价值?什么不适合你?您收到了什么错误消息?我需要从tbl_用户那里检索分数值,其中用户名为txtUser.text
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
'Check if username or password fields are empty
If txtUsername.Text = "" Or txtPassword.Text = "" Then
MessageBox.Show("Please complete the required fields", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
'Declare connection to database
'OleDb = Object Linking and Embedding, Database
Dim connDB As New System.Data.OleDb.OleDbConnection()
'Location of Access Database
connDB.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Year 12\Information Technology\Programming\WindowsApplication2\userDatabase.accdb"
Try
'Holds the username and password
Dim sql As String = "SELECT * FROM tbl_user WHERE User='" & txtUsername.Text & "' AND Pass= '" & txtPassword.Text & "'"
Dim sqlCom As New System.Data.OleDb.OleDbCommand(sql)
'Open database connection
sqlCom.Connection = connDB
connDB.Open()
Dim sqlRead As System.Data.OleDb.OleDbDataReader = sqlCom.ExecuteReader()
'If username and password validated then display game form
If sqlRead.Read() Then
Me.Hide()
frmGame.Show()
Else
'Authentication failure message
MessageBox.Show("Incorrect username or password", "Authentication Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtUsername.Text = ""
txtPassword.Text = ""
txtUsername.Focus()
End If
'Database connection failure message
Catch ex As Exception
MessageBox.Show("Connection to User Database failed" & ex.Message, "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub