兄弟,这里出错了: if (table.Rows.Count > 0)
{
//MessageBox.Show("登录成功!");
Form f3 = new Form3();
f3.Show();
//this.Hide();
}
是这样的: From3 f3=new Form3();
f3.Show();
你再试试
{
//MessageBox.Show("登录成功!");
Form f3 = new Form3();
f3.Show();
//this.Hide();
}
是这样的: From3 f3=new Form3();
f3.Show();
你再试试
解决方案 »
- 串口接收数据怎么直接转成中文?
- 100分请大家研究一下,如何使用HttpWebRequest登录博客大巴?
- 急!反射时如何来识别某个参数是个 params 变量?
- [求助]关于windows窗体编程的问题
- 周期性执行某个功能,用哪一种方法好?(Timer、Sleep、WaitOne)
- OracleClient怎样获得?
- 如何在子类对象中调用父类或爷类:)的同名方法?(该方法不是虚方法)
- 如何将DATAGRIDVIEW数据导入到CRYSTAL REPORTVIEWER,希望有源码,谢谢
- 关于VB.NET中数据插入失败的问题
- CheckBox前面的那个对号太丑了,根本不支持变化颜色,谁可以使他支持多种颜色?
- 关于xml 解析问题
- webbrowser如何模拟向百度编辑器填充数据,快疯了
{
if (button1.Text != "")
{
Form form2 = new Form2();
form2.Show(); this.Hide();
} }你可以改成成员变量试一试。
//加载记录用户名状态
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserName"] != null && Session["UserPwd"] != null)
{
Session["UserName"] = null;
Session["UserPwd"] = null;
}
}
//从新跳转到注册页面
protected void ImgBtnzhuce_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("zhuce.aspx"); //跳转到注册页面中
}
//登录事件如果成功跳转到相应页面
protected void ImgBtnLogin_Click(object sender, ImageClickEventArgs e)
{
int i = this.checkLogin(this.TxtName.Text, this.TxtPwd.Text);
if (i > 0)
{
Session["UserName"] =this.TxtName.Text;
Session["UserPwd"] = this.TxtPwd.Text;
Response.Redirect("Default.aspx");//登录成功后跳转到Default.aspx页面中
}
else//调用方法调用失败,弹出提示对话框
{
Response.Write("<script language=javascript>alert('很遗憾,用户名称或密码错误!');location='javascript:history.go(-1)'</script>");
}
}
//检测数据库用户名密码填写是否正确checkLogin事件
public int checkLogin(string loginName, string loginPwd)
{
SqlConnection con = new SqlConnection(Memobwl.GetConStr());
SqlCommand myCommand = new SqlCommand("select count(*) from tb_Login where name=@loginName and Pwd=@loginPwd ", con);
myCommand.Parameters.Add(new SqlParameter("@loginName", SqlDbType.VarChar, 50));
myCommand.Parameters["@loginName"].Value = loginName;
myCommand.Parameters.Add(new SqlParameter("@loginPwd", SqlDbType.VarChar, 50));
myCommand.Parameters["@loginPwd"].Value = loginPwd;
myCommand.Connection.Open();//打开数据库连接
int i = (int)myCommand.ExecuteScalar();//执行SQL语句
myCommand.Connection.Close();//关闭数据库连接
return i;
}
而且select语句这样写,如果登陆不成功,很难判断到底为什么不成功
你应该这样写:select * from 表 where 用户名=''
判断行数大于0之后,再验证密码是否相同
这样才好区分是用户名不存在,还是密码错误.
不要把用户名和密码一起用来查询
{
//MessageBox.Show("登录成功!");
Form f3 = new Form3();
f3.Show();
//this.Hide();
}
这里要加else啊,提示到底怎么了
不要行数为0,点了就没反应了啊
用户名或密码错误!可以debug的时候,把sql的值拿出来执行,看看有没有结果。
table.Clear();//这里不是Clear了???
adapter.Fill(table);
这样你才能看出到底是用户名错误,还是密码错误
然后再对比数据库里的字段,看到底哪里没有匹配上
string mima = textBox1.Text;
DataClasses1DataContext linq = new DataClasses1DataContext("Data Source=" + IP + ";Initial Catalog=XIAOBIAODI;Persist Security Info=True;User ID=dyp;Password=5219930407");
var result = from v in linq.xinxi
where v.GONGHAO == gonghao && v.MIMA == mima
select v;
if (result.Count() > 0)
{ Form1 fm1 = new Form1();
fm1.comboBox1.Items.Add(gonghao);
fm1.comboBox1.Items.Add(mima);
var result1 = from bian in linq.xinxi
where bian.GONGHAO == gonghao
select bian;
foreach (xinxi li in result)
{
fm1.comboBox1.Items.Add(li.QUANXIAN1);
fm1.comboBox1.Items.Add(li.QUANXIAN2);
}
fm1.label1.Text = "1"; //ID = gonghao; // if (!File.Exists("C:\\Program Files\\Q test\\ID.txt"))
// {
// FileStream fs = new FileStream("C:\\Program Files\\Q test\\ID.txt", FileMode.Create, FileAccess.Write);
// StreamWriter sw = new StreamWriter(fs);
// sw.WriteLine(ID);
// sw.Close();
// fs.Close();
// }
// else
// {
// string aa = File.ReadAllText("C:\\Program Files\\Q test\\ID.txt");
// FileStream fs = new FileStream("C:\\Program Files\\Q test\\ID.txt", FileMode.Open, FileAccess.Write);
// StreamWriter sr = new StreamWriter(fs);
// sr.WriteLine(ID + "\r\n" + aa);
// sr.Close();
// fs.Close();
// }
Program.context.MainForm = fm1;
fm1.Show();
this.Close();
string connString = "Database=db_mrcy;Data Source=localhost;User Id=root;Password=111;pooling=false;CharSet=utf8;port=3306";
string sql = "select * from tb_user where UserName='" + textBox1.Text + "' and UserPwd ='" + textBox2.Text + "'";
using (MySqlConnection conn1 = new MySqlConnection(connString))
{
conn1.Open();
using (MySqlDataAdapter sda = new MySqlDataAdapter(sql, conn1))
{
// DataSet ds = new DataSet();
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count > 0)
{
MessageBox.Show("登录成功");
}
else
{
MessageBox.Show("登录失败");
}
}
}