Okay guys, I'm doing a bank application for my school project where I combine Microsoft Access with Visual Studio, I have the information in Access and I retrieve them with Visual Studio.
OleDbConnection connection;
yhteys = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source= tilit.accdb");
try
{
connection.Open();
}
catch (OleDbException tietokantavika)
{
Console.WriteLine("No connection!\n" + tietokantavika.Message);
return;
}
OleDbCommand haekomento = new OleDbCommand();
haekomento.Connection = yhteys;
haekomento.CommandText = "Select clientnumber, accountNumber,pinCode, money FROM Account";
OleDbDataReader lukija = haekomento.ExecuteReader();
while (lukija.Read())
{
string accountNumber2 = (string)lukija["accountNumber"];
int pinCode2 = (int)lukija["pinCode"];
decimal money2 = (decimal)lukija["money"];
int clientNumber2 = (int)lukija["clientNumber"];
if ((txtAccountNumber.Text == accountNumber2) && int.Parse(pinCode.Text) == pinCode2)
{
Menu GoToMenu = new Menu();
GoToMenu.Show();
}
else
lblväärä.Text = "Wrong pin or account!";
So I log in with the accountNumber 1111-1111 and pincode 1111 which is registered to Steve Bush
The problem here is that when I log in and get to the Menu form it logs in as the wrong user. It should log in as Steve Bush (clientNumber 1) but instead it logs in as Greg Ott (clientNumber 3). I think the problem is because I keep using the same connection, but I dont know how to fix it. My form 2
OleDbConnection connection;
yhteys = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source= tilit.accdb");
try
{
connection.Open();
}
catch (OleDbException tietokantavika)
{
Console.WriteLine("No connection!\n" + tietokantavika.Message);
return;
}
OleDbCommand haekomento = new OleDbCommand();
haekomento.Connection = yhteys;
haekomento.CommandText = "Select clientNumber, firstName, lastName FROM Client";
OleDbDataReader lukija = haekomento.ExecuteReader();
while (lukija.Read())
{
int clientNumber2 = (int)lukija["clientNumber"];
string lastName2 = (string)lukija["lastName"];
string firstName2 = (string)lukija["firstName"];
lblNimi.Text = "Welcome" + firstName2 + lastName2; // Here it should display Steve Bush but instead it says Greg Ott
I know i've made alot of mistakes in that code, that's why I came here for help. I've been stuck with this for hours and dont know how to fix it.