我想通過從sql數據庫中輸入他們的pin號碼來登錄的選定的卡號,然後我需要匹配選定的卡號來檢索它們從數據庫中取得平衡並將其顯示在一個富文本框中。我已經能夠從數據庫中獲取PIN碼並將其與用戶cardnumber匹配,以使他們能夠訪問表格2,但是我發現很難從form1上的組合框中選取所選卡號並使用它來檢索所選內容用戶平衡一次我點擊平衡按鈕,並將其顯示在form2 richtextbox上。我有以下代碼:將選定的值CardNumber組合框在form1上形成2
public partial class Form1 : Form
{
public int logAttempts = 3;
public string accountNo;
public Form1()
{
InitializeComponent();
}
private void btnCancel_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void BtnEnter_Click(object sender, EventArgs e)
{
int index = cBCardNumber.SelectedIndex;
DataRow dpin = dataSet1ATMCards.Tables["ATMCards"].Rows[index];
String pin = dpin.ItemArray.GetValue(1).ToString();
if (textBoxPin.Text.Length == 4)
{
if (String.Equals(pin, textBoxPin.Text))
{
Form2 frm2;
frm2 = new Form2();
frm2.ShowDialog();
}
else
{
if (loginAttempts == 1)
{
sqlCommandConfiscated.Parameters["@cardNumber"].Value = cBCardNumber.Text;
sqlCommandConfiscated.Parameters["@confiscated"].Value = true;
try
{
sqlCommandConfiscated.Connection.Open();
sqlCommandConfiscated.ExecuteNonQuery();
MessageBox.Show("You have reached your maximum login attempts.");
textBoxPin.Clear();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sqlCommandConfiscated.Connection.Close();
}
}
else
{
loginAttempts--;
MessageBox.Show("You have entered the Wrong Pin. You have " + loginAttempts);
}
}
}
else
{
MessageBox.Show("Please enter your 4 digit Pin Number");
}
}
private void Form1_Load(object sender, EventArgs e)
{
sqlDataAdapter1.Fill(dataSet1ATMCards.ATMCards);
}
private void cBCardNumber_SelectedIndexChanged(object sender, EventArgs e)
{
loginAttempts = 3;
}
}
}