0
我有這樣的代碼在我btnLogin
在Form1
從MS Access database
獲得的數據,我想它使用標籤在Form2
顯示,但我不知道如何將它傳遞到Form2
檢索數據並顯示它以另一種形式標記
private void btnLogin_Click(object sender, EventArgs e)
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
if ((this.txtUser.Text == "admin") && (this.txtPass.Text == "admin"))
{
Form1 main = new Form1();
main.txtHere.Text = txtUser.Text;
main.Show();
this.Hide();
}
else {
command.CommandText = "select * from StudentsTBL where LastName='" + txtUser.Text + "' and FirstName='" + txtPass.Text + "'";
OleDbDataReader reader = command.ExecuteReader();
int count = 0;
while (reader.Read()) {
count = count + 1;
//count++;
}
if (count == 1) {
MessageBox.Show("Login Successful!");
List<String> stdNo = new List<String>();
List<String> middleName = new List<String>();
List<String> section = new List<String>();
List<String> year = new List<String>();
List<String> sem = new List<String>();
List<String> address = new List<String>();
List<String> dob = new List<String>();
List<String> gender = new List<String>();
List<String> age = new List<String>();
List<String> contact = new List<String>();
List<String> desc = new List<String>();
command = new OleDbCommand("select * from StudentsTBL", connection);
reader = command.ExecuteReader();
while (reader.Read())
{
stdNo.Add(reader["StudentNo"].ToString());
middleName.Add(reader["Middle"].ToString());
section.Add(reader["stdSection"].ToString());
year.Add(reader["stdYear"].ToString());
sem.Add(reader["stdSem"].ToString());
address.Add(reader["stdAddress"].ToString());
dob.Add(reader["stdDob"].ToString());
gender.Add(reader["stdGender"].ToString());
age.Add(reader["stdAge"].ToString());
contact.Add(reader["ContactNo"].ToString());
desc.Add(reader["stdDesc"].ToString());
}
StudentProfile stdProfile = new StudentProfile(txtUser.Text, txtPass.Text);
stdProfile.Show();
this.Hide();
}
else if (count > 1)
{
MessageBox.Show("Duplicate username and password!!");
}
else {
MessageBox.Show("Login Failed!");
}
}
connection.Close();
}
來源:Getting data from MS Access database and display it in a listbox
嗯,什麼'Form2'? 'Label'字段的名稱是什麼? – MickyD 2015-02-24 00:00:40
我想顯示數據到'form2' – user3833309 2015-02-24 00:04:01
[Forms are just classes](http://www.contrivedexample.com/ce/post/2015/02/15/forms-are-just-classes.aspx) – Crowcoder 2015-02-24 00:09:17