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
}
}
}
我希望在登录成功时激活“编辑标签页”。 “编辑页面”是其他形式。
答案 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。