cn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; cmd.CommandText = "select * from dbo.工作微博 where 姓名='" + textBox1.Text + "' and 密码 ='" + textBox2.Text + "'"; cmd.CommandType = CommandType.Text;
cmd.ExecuteReader(); if () {
switch () { case "0": Form2 f2 = new Form2(); f2.Show(); break;//break一定不能少! case "1": Form3 f3 = new Form3(); f3.Show(); break; case "2": Form1 f1 = new Form1(); f1.Show(); break; } } if那应该怎么写呢?查到登录名再根据登录名查权限,再根据权限进入不同的界面
cmd.CommandType = CommandType.Text;
cmd.ExecuteReader();
if ("Select 权限 from dbo.工作微博 where 姓名='" + textBox1.Text + "'"=="0")
{
Form2 f2 = new Form2();
f2.Show();
}else if ("Select 权限 from dbo.工作微博 where 姓名='" + textBox1.Text + "'"=="1")
{
Form3 f3 = new Form3();
f3.Show();
} else
{
Form1 f1 = new Form1();
f1.Show();
} 请大侠们帮着改改可以吗?着急解决,现在数据库里查询登录名,如果数据库中有在查权限,根据权限进入不同的界面。谢谢,有点急!!!
这个框架很符合你的要求,并且帮你做了很多的设计:http://www.cnblogs.com/allen0118/archive/2012/05/10/2494112.html
private void button1_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection();
cn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["china"].ConnectionString;
cn.Open();
SqlCommand cmd = new SqlCommand();
if (comboBox1.Text == "读者")
{
string str=string.Format("select rno,rpwd from reader where rno='{0}'and rpwd='{1}'",textBox1.Text.Trim(),textBox2.Text.Trim());
cmd.CommandText=str;
cmd.Connection=cn;
SqlDataReader dr=cmd.ExecuteReader();
if(dr.Read()){
pwd = textBox2.Text.Trim();//密码
userid = textBox1.Text.Trim();
reader r=new reader();
r.Show();
this.Hide();
}
else
{ MessageBox.Show("用户名或密码错误");
textBox1.Text = null;
textBox2.Text = null;
}
}
else if (comboBox1.Text == "管理人员") {
string str = string.Format("select mno,mpwd from management where mno='{0}'and mpwd='{1}'", textBox1.Text.Trim(), textBox2.Text.Trim());
cmd.CommandText = str;
cmd.Connection = cn;
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
pwd = textBox2.Text.Trim();//密码
userid = textBox1.Text.Trim();
manager m = new manager();
m.Show();
this.Hide();
}
else
{ MessageBox.Show("用户名或密码错误");
textBox1.Text = null;
textBox2.Text = null;
}
}
else { MessageBox.Show("请选着职称");
textBox1.Text = null;
textBox2.Text = null;
}
}
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "select * from dbo.工作微博 where 姓名='" + textBox1.Text + "' and 密码 ='" + textBox2.Text + "'";
cmd.CommandType = CommandType.Text;
cmd.ExecuteReader();
if ()
{
switch ()
{
case "0":
Form2 f2 = new Form2();
f2.Show();
break;//break一定不能少!
case "1":
Form3 f3 = new Form3();
f3.Show();
break;
case "2":
Form1 f1 = new Form1();
f1.Show();
break; }
}
if那应该怎么写呢?查到登录名再根据登录名查权限,再根据权限进入不同的界面