我已经创建了一个正常工作的登录表单但是我试图做的是在用户登录后我需要将帐号存储在某个地方以便我可以保存它。
这是我的按钮点击事件方法
private void button1_Click(object sender, EventArgs e)
{
string accNumMain = "";
Menu m1 = new Menu();
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=ATM_Database.accdb; Persist Security Info=False;";
OleDbDataReader dr = null;
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
try
{
conn.Open();
string query = "Select Customer_ID,Password from Customer where Customer_ID = '" + this.userBox.Text + "' and Password = '" + this.Password.Text + "'";
OleDbCommand cmd = new OleDbCommand(query, conn);
cmd.Parameters.AddWithValue("@Customer_ID ", this.userBox.Text);
cmd.Parameters.AddWithValue("@Password ", this.Password.Text);
dr = cmd.ExecuteReader();
if (dr.HasRows == true)
{
while (dr.Read())
{
accNumMain = userBox.Text;
Classes.AccSave AC1 = new Classes.AccSave(accNumMain);
MessageBox.Show("Welcome");
this.Hide();
m1.Show();
}
}
else
{
wrongEntry_Lable.Visible = true;
}
}
finally
{
Console.ReadLine();
if (dr != null)
{
dr.Close();
}
if (conn != null)
{
conn.Close();
}
}
}
}
我所做的是将上下文保存到一个新类中:
class AccSave
{
string acc { get; set; }
public AccSave(string acc)
{
this.acc = acc;
}
}
}
我无法从另一个类调用此类以访问其中包含 AccNum 的字符串 var