
C#登陆界面 寻错 急!!!!!!!!!! 调试时不报错 但点击button1却无反应 “管理员”为用户名之一
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Collections;
namespace WindowsApplication11
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = Class1.createConnection();
conn.Open();
SqlCommand cmd = new SqlCommand("",conn);
string sql = "selcet * from DL where 用户名='" + textBox1.Text.Trim ().ToString() + "'and 密码='" + textBox2.Text.Trim ().ToString() + "'";
cmd.CommandText =sql;
SqlDataReader rd = cmd.ExecuteReader();
if (rd.GetSqlString(0)=="管理员")
{
this.Hide();
Form2 Form2 = new Form2();
Form2.Show();
conn.Close();
this.Close();
}
else
{
MessageBox.Show("用户名或密码错误", "登录失败");
}
}
}
} 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Collections;
namespace WindowsApplication11
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = Class1.createConnection();
conn.Open();
SqlCommand cmd = new SqlCommand("",conn);
string sql = "selcet * from DL where 用户名='" + textBox1.Text.Trim ().ToString() + "'and 密码='" + textBox2.Text.Trim ().ToString() + "'";
cmd.CommandText =sql;
SqlDataReader rd = cmd.ExecuteReader();
if (rd.GetSqlString(0)=="管理员")
{
this.Hide();
Form2 Form2 = new Form2();
Form2.Show();
conn.Close();
this.Close();
}
else
{
MessageBox.Show("用户名或密码错误", "登录失败");
}
}
}
} 展开
展开全部
你这个点击时没有反应,让我很纠结、、、难道是你事件写错了么。怎么可能没反应。我COPY你的代码运行的时候,点按钮会报错,rd.GetSqlString(0)这个方法我没用过,你有没有想过这样子,要是你没找到数据,会报错、、、
建议你判断这样的语句的时候改用selcet count(*) from DL where....
int i =Convert.ToInt32(cmd.ExecuteScalar());
再去判断I的大小,如果大于0就说明有这样的记录。
建议你判断这样的语句的时候改用selcet count(*) from DL where....
int i =Convert.ToInt32(cmd.ExecuteScalar());
再去判断I的大小,如果大于0就说明有这样的记录。
展开全部
设置断点跟踪吧
不过从表面上看
if (rd.GetSqlString(0)=="管理员")
这个判断有问题
不过从表面上看
if (rd.GetSqlString(0)=="管理员")
这个判断有问题
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
设置断点或者逐步逐步看一下,你这么说很难看得出哪出问题了的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不会是点击事件 没有绑定上 或者绑定错误吧 。。。你设个断点 看程序能不能进来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询