用户可以登陆,而管理员却不可以登陆了
代码都差不多,请帮帮我啊
作品还很多功能没有完成
初学c#,请斑竹多多指教
数据库outin
表user ------- name,pwd
表guest ----- Name,Pwd
private void button2_Click(object sender, System.EventArgs e)
{
//管理员验证身份
if(textBox3.Text==""&&textBox4.Text=="")
{
MessageBox.Show("username or userpwd is not null","cuowu ");
this.textBox3.Focus();
}
else
{
try
{
string cstring="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=outin.mdb";
OleDbConnection MyCon=new OleDbConnection(cstring);
MyCon.Open();
OleDbCommand cmd=new OleDbCommand("Select count(*) From user where name='"+this.textBox3.Text+"'and pwd='"+this.textBox4.Text+"'",MyCon);
//OleDbCommand cmd=new OleDbCommand("Select count(*) From guest where Name='"+this.textBox1.Text+"' and Pwd='"+this.textBox2.Text+ "'",MyCon);
int count=Convert.ToInt32(cmd.ExecuteScalar());
if(count>0)
{
user us=new user();
us.MdiParent=this.MdiParent;
us.Show();
this.Close();
}
else
{
MessageBox.Show("cuowu","shibai");
}
MyCon.Close();
}
catch (Exception ex)
{
MessageBox.Show("fff"+ex.ToString());
}
}
}
private void button1_Click(object sender, System.EventArgs e)
{
//用户验证身份
if(textBox1.Text==""&&textBox2.Text=="")
{
MessageBox.Show("username or userpwd is not null","cuowu ");
this.textBox1.Focus();
}
else
{
try
{
string cstring="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=outin.mdb";
OleDbConnection MyCon=new OleDbConnection(cstring);
MyCon.Open();
OleDbCommand cmd=new OleDbCommand("Select count(*) From guest where Name='"+this.textBox1.Text+"' and Pwd='"+this.textBox2.Text+ "'",MyCon);
int count=Convert.ToInt32(cmd.ExecuteScalar());
if(count>0)
{
guest form2=new guest();
form2.MdiParent=this.MdiParent;
form2.Show();
this.Close();
}
else
{
MessageBox.Show("cuowu","shibai");
}
MyCon.Close();
}
catch (Exception ex)
{
MessageBox.Show("fff"+ex.ToString());
}
}
[此贴子已经被作者于2005-12-11 22:23:33编辑过]
OleDbCommand cmd=new OleDbCommand("Select count(*) From user where name='"+this.textBox3.Text+"'and pwd='"+this.textBox4.Text+"'",MyCon);
//OleDbCommand cmd=new OleDbCommand("Select count(*) From guest where Name='"+this.textBox1.Text+"' and Pwd='"+this.textBox2.Text+ "'",MyCon);
name吧。那个n到底是大写还是小写,唉,这些都是细心问题。
它提示语法错一般就是SQL语句写错了。
[此贴子已经被作者于2005-12-12 8:52:44编辑过]