简体   繁体   English

C#WInform,将下一个值传递给下一个表单,HOW

[英]C# WInform ,Passing next value to the next form, HOW

how will I pass data from database to the next Winform, like in php called session) 我如何将数据从数据库传递到下一个Winform,例如在称为session的php中)

I wanted to show, a welcome message showing NICKNAME on the 2nd form, instead of USER ID, Please show me in most easiest way, Thanks 我想显示一条欢迎消息,在第二个表单上显示NICKNAME,而不是USER ID,请以最简单的方式显示给我,谢谢

Below is my code for Loginpage: 以下是我登录页面的代码:

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();
}

you can create constructor in Form2 to accept nickname 您可以在Form2中创建构造函数以接受昵称

public Form2(string nickname)
{
  InitializeComponent(); 
  label1.Text=nickname;
}

in your 1st page, read the nickname from myReader and pass it to Form2 在您的第一页中,从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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM