好的,我正在为我的学校项目做一个银行申请,我将 Microsoft Access 与 Visual Studio 结合起来,我在 Access 中有信息,我用 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!";
所以我用注册给史蒂夫布什的账号 1111-1111 和密码 1111 登录
这里的问题是,当我登录并进入菜单表单时,它以错误的用户身份登录。它应该以 Steve Bush (clientNumber 1) 的身份登录,但它以 Greg Ott (clientNumber 3) 的身份登录。我认为问题是因为我一直使用相同的连接,但我不知道如何解决它。我的表格 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
我知道我在该代码中犯了很多错误,这就是我来这里寻求帮助的原因。我已经坚持了几个小时,不知道如何解决它。