-2
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 
    }
  }
}

I want to activate the "edit tabpage" when the login suceeds . The "edit page " is in other form.

ajshort
  • 3,684
  • 5
  • 29
  • 43

1 Answers1

0

This might do the trick for you.

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

It is suggested that you should use Parameterized Query to prevent SQL Injection.

Community
  • 1
  • 1
Mohit S
  • 13,723
  • 6
  • 34
  • 69
  • Thanks for the sugesstion. but " frm.tabpage " not working. – Kogul Vimal Jan 28 '16 at 05:09
  • `Form1 frm = new Form1(); frm.NameOfTabControl.SelectedIndex = 1;frm.Show();` – Jeremy Thompson Jan 28 '16 at 05:29
  • Hi @KogulVimal if this or any answer has solved your question please consider [accepting it](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Mohit S Jan 29 '16 at 03:23