我在我的项目中有两个表单(Form1和Form2)。
在Form1中,我有两个文本框,就像“登录”表单一样,要求用户输入用户名(textboxUsername)和密码(textboxPassword)。当用户登录后,Form2弹出。
现在,在Form2中,我有一个button1和dataGridView1。当我按下button1时,我想显示在Form1中输入的所选用户(textboxUsername)。
我想根据保存在SQL Server中的用户名获取该用户。
Form2 button1代码:
在这种情况下,我想在 Form2 中调用 Form1 的 textBoxUsername 部分的代码是:
在Form1中,我有两个文本框,就像“登录”表单一样,要求用户输入用户名(textboxUsername)和密码(textboxPassword)。当用户登录后,Form2弹出。
现在,在Form2中,我有一个button1和dataGridView1。当我按下button1时,我想显示在Form1中输入的所选用户(textboxUsername)。
我想根据保存在SQL Server中的用户名获取该用户。
Form2 button1代码:
private void button1_Click(object sender, EventArgs e)
{
string constring = @"Data Source=V-K\;Initial Catalog=ATMKlientet;Integrated Security=True";
SqlConnection conDataBase = new SqlConnection(constring);
SqlCommand cmdDataBase = new SqlCommand(" select * from Clients ;", conDataBase);
try
{
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmdDataBase;
dbdataset = new DataTable();
sda.Fill(dbdataset);
BindingSource bSource = new BindingSource();
bSource.DataSource = dbdataset;
dataGridView1.DataSource = bSource;
sda.Update(dbdataset);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
在这种情况下,我想在 Form2 中调用 Form1 的 textBoxUsername 部分的代码是:
(" select * from Clients where Username='" + this.textBoxUsername + "';", conDataBase);