[英]C# WInform ,Passing next value to the next form, HOW
我如何將數據從數據庫傳遞到下一個Winform,例如在稱為session的php中)
我想顯示一條歡迎消息,在第二個表單上顯示NICKNAME,而不是USER ID,請以最簡單的方式顯示給我,謝謝
以下是我登錄頁面的代碼:
try //***************TRY START****************
{
OleDbCommand cmd = new OleDbCommand("Select * from Account where User_ID='" + userID.Text + "' and Pass='" + Password.Text + "';", con);
OleDbDataReader myReader;
con.Open();
myReader = cmd.ExecuteReader();
int count = 0;
while (myReader.Read())
{
count = count + 1;
}
if (count == 1)
{
string s = userID.Text;
MessageBox.Show(s);
this.Hide();
AdminPanel us = new AdminPanel();
us.Show();
}
else
{
MessageBox.Show("Invalid ");
}
con.Close();
} // ******END TRY********
catch (Exception ex)
{
MessageBox.Show(ex.Message);
con.Close();
}
您可以在Form2中創建構造函數以接受昵稱
public Form2(string nickname)
{
InitializeComponent();
label1.Text=nickname;
}
在您的第一頁中,從myReader
讀取昵稱並將其傳遞給Form2
con.Open();
OleDbDataReader myReader= cmd.ExecuteReader();
if(myReader.Read())
{
string nickname= myReader["Nickname"].ToString(); // give correct column name as your database
Form2 frm=new Form2(nickname);
frm.Show();
}else
{
MessageBox.Show("Invalid ");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.