关于登录页面 用C# .net web怎样在Button里面写代码判断TextBox里面的登录名和密码与数据库中的相比较,如果输入框中的内容与数据库的一致,则能跳转到一个主页。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 很多种方法 例如: 写一个查询方法 然后查询数据库中 有没有你传入的 登录名和密码 如果有 返回一条数据 存进集合里面 判断集合的count 如果>0 则此用户存在~ 这是最简单 也是 最不严谨的~ 这种方法试过了 总是出现错误竟然 protected void Button1_Click(object sender, EventArgs e) { string name = TextBox1.Text.Trim(); string pw = TextBox2.Text.Trim(); DBAcess db = new DBAcess(); string sql = string.Format("select name,pw from student where name='{0}' and pw='{1}'", name, pw); DataSet ds = new DataSet(); ds = db.GetDataSet(sql); if(ds.Tables[0].Rows.Count>0){ Response.Redirect("http://localhost:49178/important.aspx"); }看看有什么错误 OleDbConnection conn = new OleDbConnection("数据库连接字符串(LZ是操作本地数据库Access吧那我就按你的操作)"); try { conn.Open(); string sql = string.Format("select name,pw from student where name='{0}' and pw='{1}'", name, pw); OleDbCommand cmd = new OleDbCommand(sql,conn); OleDbDataAdapter oda = new OleDbDataAdapter(); oda.SelectCommand = cmd; DataSet ds = new DataSet(); DataTable dt = new DataTable(); oda.Fill(ds); dt = ds.Tables[0]; ................ } SQL:select count(*) from student where name='{0}' and pw='{1}'.把查到的值返回到CS的Count。CS:if (Count>0){ //Continu}else{ //Back} SQL:select count(*) from student where name='0' and pw='1' 菜鸟求教 求助:WCF ICP问题 请教streamWriter的writeLine方法的数据覆盖问题 Tab选项卡为什么会乱? TcpClient TcpListener能传送自定义报文格式流吗? C#应用程序打包问题!!!顶者有分!!! 怎样得到指定目录下,所有文件的文件名列表?谢谢! winForm 中 axWebBrowser 使用 SendKeys 的问题 请教有关C#的byte类型数值移位的问题: webservice关闭连接 求思路了~ TableLayoutPanel如何删除其中某一行
这是最简单 也是 最不严谨的~
protected void Button1_Click(object sender, EventArgs e)
{
string name = TextBox1.Text.Trim(); string pw = TextBox2.Text.Trim(); DBAcess db = new DBAcess();
string sql = string.Format("select name,pw from student where name='{0}' and pw='{1}'", name, pw); DataSet ds = new DataSet(); ds = db.GetDataSet(sql);
if(ds.Tables[0].Rows.Count>0){
Response.Redirect("http://localhost:49178/important.aspx");
}看看有什么错误
OleDbConnection conn = new OleDbConnection("数据库连接字符串(LZ是操作本地数据库Access吧那我就按你的操作)");
try
{
conn.Open();
string sql = string.Format("select name,pw from student where name='{0}' and pw='{1}'", name, pw);
OleDbCommand cmd = new OleDbCommand(sql,conn);
OleDbDataAdapter oda = new OleDbDataAdapter();
oda.SelectCommand = cmd;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
oda.Fill(ds);
dt = ds.Tables[0];
................
}
把查到的值返回到CS的Count。
CS:
if (Count>0)
{
//Continu
}
else
{
//Back
}