C# 用户登录后从登录页面进行导航
这是我登录页面的代码。但在用户登录后没有“导航”编码。需要一些帮助来编写此代码。(导航到下一个表单的导航代码)C# 用户登录后从登录页面进行导航,c#,sql,sql-server,login,C#,Sql,Sql Server,Login,这是我登录页面的代码。但在用户登录后没有“导航”编码。需要一些帮助来编写此代码。(导航到下一个表单的导航代码) 欢迎来到stackoverflow!您能否将代码最小化到相关的程度和/或描述您期望的内容?这样你可能会得到更好的答案。谢谢你,这很有效。我还可以知道如何根据用户级别从登录表单设置不同的导航-例如,如果管理员登录,则指向管理员表单;如果员工登录,则指向员工表单 namespace WindowsFormsApplication2 { public partial class Fo
欢迎来到stackoverflow!您能否将代码最小化到相关的程度和/或描述您期望的内容?这样你可能会得到更好的答案。谢谢你,这很有效。我还可以知道如何根据用户级别从登录表单设置不同的导航-例如,如果管理员登录,则指向管理员表单;如果员工登录,则指向员工表单
namespace WindowsFormsApplication2
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
private void Form5_Load(object sender, EventArgs e)
{
using(SqlConnection myconnection = new SqlConnection("Data Source=chariths-bently\\charith;Initial Catalog=emp_mgt;Integrated Security=True"))
{
}
}
private void login_Click(object sender, EventArgs e)
{
if (ok(username.Text, password.Text) > 0)
MessageBox.Show("Access granted");
else
MessageBox.Show("access denied");
}
private int ok( string username, string password)
{
username.Trim();
password.Trim();
SqlDataReader dr = null;
using(SqlConnection myconnection = new SqlConnection("Data Source=chariths-bently\\charith;Initial Catalog=emp_mgt;Integrated Security=True"))
{
myconnection.Open();
string query = "select * from emp_info ";
SqlCommand cmd = new SqlCommand(query,myconnection);
if(cmd.ExecuteScalar () != null)
return 1;
else
return 0;
}
}
}
}
private void login_Click(object sender, EventArgs e)
{
if (ok(username.Text, password.Text) > 0)
{
MessageBox.Show("Access granted");
Form6 f6 = new Form6(); // create your next form instance,(form6, for example)
f6.Open();
this.Close();
}
....
}