Reputation: 87
I am trying to create a Banking windows form as an assignment.
I am able to log users in with the below code. It reads from an MS Access database:
myConnection.ConnectionString = connString
myConnection.Open()
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Account WHERE Customer_Id = (SELECT [ID] FROM Customer WHERE Cust_Name = '" & txtName.Text & "') AND PIN =" & Convert.ToInt32(txtPin.Text) & ";", myConnection)
Dim dr As OleDbDataReader = cmd.ExecuteReader
Dim userFound As Boolean = False
While dr.Read
userFound = True
loggedInName = txtName.Text
End While
Now, I am trying to retrieve the Balance value from the Account table for the user which has just logged in.
Is there a way to use the above code to do that? If not, then what is the best way?
Upvotes: 0
Views: 33
Reputation: 9193
Use the Item Property of the DataReader to get your value:
While dr.Read
userFound = True
loggedInName = txtName.Text
Dim dblBalance As Double = 0.0
'This shouldn't be a nullable field, but just in case:
If dr.Item("Balance") <> DBNull.Value Then
dblBalance = Convert.ToDouble(dr.Item("Balance"))
End If
End While
Upvotes: 2