如何通过点击其他表单的按钮来显示标签页

时间:2016-01-28 04:35:05

标签: c# tabpage

private void btnLogin_Click(object sender, EventArgs e)
{
  Form1 frm = new Form1();
  string sql = "SELECT * From Admin WHERE UserName='" + txtUserName.Text + "' And Password='"+txtPassword.Text+"'";

  if (conn2.State != ConnectionState.Open)
  {
    conn2.Open();
  }

  command = new SqlCommand(sql, conn2);
  SqlDataReader reader = command.ExecuteReader();
  reader.Read();

  if (reader.HasRows)
  {
    if(reader[0]==txtUserName.Text   && reader[1]==txtPassword.Text)
    {
      // I want the code in this section 
    }
  }
}

我希望在登录成功时激活“编辑标签页”。 “编辑页面”是其他形式。

1 个答案:

答案 0 :(得分:0)

这可能适合你。

int indexyouwant = 1; // Suppose 1 is your Edit Page Tab. 
Form1 frm = new Form1();
// SQL 
if (reader.HasRows)
{
    if(reader[0]==txtUserName.Text   && reader[1]==txtPassword.Text)
    {
        frm.YourTabControlName.SelectedIndex = indexyouwant;
    }
}

建议您使用参数化查询来阻止SQL Injection