if (users.Text.Trim().Length > 0 && password.Text.Trim().Length > 0)
{
base.Cursor = Cursors.WaitCursor;
//从mysql数据库读取数据进行比对
MySQLConnection DBConn;
DBConn = new MySQLConnection(new MySQLConnectionString("localhost", "mybase", "root", "tizheng", 3306).AsString);
DBConn.Open();
// MySQLCommand conn = new MySQLCommand("set names gb2312", DBConn);
// conn.ExecuteNonQuery();
MySQLCommand cmd = new MySQLCommand("select count(*) from login where Users='" + users.Text + "' and Pwd='" + password.Text + "'", DBConn);
int flag = Convert.ToInt32(cmd.ExecuteScalar()); //数据读取标记,传递用户权限
if (flag > 1)
{
cmd = new MySQLCommand("seclect * from login Users='" + users.Text + "'", DBConn);
MySQLDataReader sdr = (MySQLDriverCS.MySQLDataReader)cmd.ExecuteReader();
sdr.Read();
string Users_Type = sdr["power"].ToString().Trim(); //不知道个地方怎么进行登陆的权限的传递,初学不是很懂,怎么传个mainFrom这个窗口啊
DBConn.Close();
this.DialogResult = DialogResult.OK;
this.Close();
}
else {
this.DialogResult = DialogResult.No;
MessageBox.Show("账号或密码不正确,请重新输入!", "登陆错误!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
} }
else
{
MessageBox.Show("账户名或密码不能为空!", "登陆错误!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
DialogResult = DialogResult.None;
}
数据库字段方面肯定没错
不知道为什么不进flag,一直提示的都是密码账户错误
{
base.Cursor = Cursors.WaitCursor;
//从mysql数据库读取数据进行比对
MySQLConnection DBConn;
DBConn = new MySQLConnection(new MySQLConnectionString("localhost", "mybase", "root", "tizheng", 3306).AsString);
DBConn.Open();
// MySQLCommand conn = new MySQLCommand("set names gb2312", DBConn);
// conn.ExecuteNonQuery();
MySQLCommand cmd = new MySQLCommand("select count(*) from login where Users='" + users.Text + "' and Pwd='" + password.Text + "'", DBConn);
int flag = Convert.ToInt32(cmd.ExecuteScalar()); //数据读取标记,传递用户权限
if (flag > 1)
{
cmd = new MySQLCommand("seclect * from login Users='" + users.Text + "'", DBConn);
MySQLDataReader sdr = (MySQLDriverCS.MySQLDataReader)cmd.ExecuteReader();
sdr.Read();
string Users_Type = sdr["power"].ToString().Trim(); //不知道个地方怎么进行登陆的权限的传递,初学不是很懂,怎么传个mainFrom这个窗口啊
DBConn.Close();
this.DialogResult = DialogResult.OK;
this.Close();
}
else {
this.DialogResult = DialogResult.No;
MessageBox.Show("账号或密码不正确,请重新输入!", "登陆错误!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
} }
else
{
MessageBox.Show("账户名或密码不能为空!", "登陆错误!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
DialogResult = DialogResult.None;
}
数据库字段方面肯定没错
不知道为什么不进flag,一直提示的都是密码账户错误
解决方案 »
- C# WinForm程序从ftp上读取txt文件中的内容
- (急)!谁帮我看看!
- ----根据控件名,查找类中是否的该属性,有则给它赋值(WinForm)------
- asp.net C#如何上传指定路径的图片,不用FileUpload控件
- 关于 webparts 的问题
- 超简单问题,我不会~谁给讲一下~散分~!
- 程序怎么设置DATEGRID中某一行中某个列的数值。
- C#的overide隐式继承一个接口和显示继承一个接口的区别?
- c#开发工具
- C# WinForm 添加Windows Media Player 控件调试出现未能加载文件或程序集Interop.WMPLib
- 【急】一个从整个数据表中提取特定部分数据的SQL语句问题
- 求助关于.NET的一个问题。..
if (flag > 0)
{
//////////////////////////
}
参考
http://www.cnblogs.com/xugang/archive/2007/09/05/883282.html
如何把这个power属性值传给mainFrom这个窗口呢