c#中登陆问题!!...急

zhanghw0704 2009-04-29 10:31:05
我在做一个html的界面 界面上有两个textbox用来登陆 ,在用户输入信息并且点击提交后 ,将数据与数据库中的数据比较 当正确就用“xxx您好”
错误就“”;
我想应该是用js获取数据库中的数据,然后与文本框中的数据匹配,不知道是不是
希望大家指点指点。。。
尽量明白点
...全文
83 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhanghw0704 2009-04-29
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 wusenbo 的回复:]
直接用服务器控件多好!!呵呵
[/Quote]
我是在html中做的ok?
你见过html中有服务器控件?
上面代码太难了看不懂,,在下一小鸟
wusenbo 2009-04-29
  • 打赏
  • 举报
回复
直接用服务器控件多好!!呵呵
explorewen 2009-04-29
  • 打赏
  • 举报
回复
c#访问sql server,登录模块,看看有你想要的东东吗
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public class ttestt_Default : System.Web.UI.Page
{
static string constring = System.Configuration.ConfigurationManager.ConnectionStrings["goodsmisdbConnectionString"].ToString();

protected void Page_Load(object sender, EventArgs e)
{
lbmsg.Text = "";
uid.Focus();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["username"] != null)
{
Session["username"] = null;
}
if (Session["usertype"] != null)
{
Session["usertype"] = null;
}
RequiredFieldValidator1.ErrorMessage = "";
string username = uid.Text.Trim();
string password = pwd.Text.Trim();
lbmsg.Text = "";
SqlConnection myConn = new SqlConnection(constring);
myConn.Open();
SqlCommand isLockCom = new SqlCommand("isLocked", myConn);
isLockCom.CommandType = CommandType.StoredProcedure;
isLockCom.Parameters.AddWithValue("@username", username);
int pd = -1;
pd = Convert.ToInt32(isLockCom.ExecuteScalar());
if (pd != 1)
{
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConn;
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "uidPwd";
myCommand.Parameters.AddWithValue("@username", username);
myCommand.Parameters.AddWithValue("@password", password);
SqlDataReader myRead = myCommand.ExecuteReader();

if (myRead.Read() == true)
{
string flag = myRead.GetValue(1).ToString();
myRead.Close();
SqlCommand myCommand2 = new SqlCommand();
myCommand2.Connection = myConn;
myCommand2.CommandType = CommandType.StoredProcedure;
myCommand2.CommandText = "SetErrTimesZero";
myCommand2.Parameters.AddWithValue("@username", username);
myCommand2.ExecuteNonQuery();
myConn.Close();

Session.Timeout = 60;
Session["username"] = uid.Text.Trim();
Session["usertype"] = flag;
Response.Redirect("~/login/default.aspx");
}
else
{
Response.Write("<script>window.alert('用户名或密码错误,请重新输入!')</script>");
myRead.Close();

SqlCommand errCommand1 = new SqlCommand();
errCommand1.Connection = myConn;
errCommand1.CommandText = "haveUserAndErr";
errCommand1.CommandType = CommandType.StoredProcedure;
errCommand1.Parameters.AddWithValue("@username", username);
SqlDataReader myRead1 = errCommand1.ExecuteReader();
if (myRead1.Read())
{
int times = (int)myRead1.GetValue(1);
myRead1.Close();
SqlCommand addErrorCom = new SqlCommand("addErrorTimes", myConn);
addErrorCom.CommandType = CommandType.StoredProcedure;
addErrorCom.Parameters.AddWithValue("@username", username);
addErrorCom.ExecuteNonQuery();
switch (times)
{
case 1:
{
lbmsg.Text = "此用户已两次输入错误口令,若再次错误用户名将被锁!";
uid.Text = "";
pwd.Text = "";
uid.Focus();
break;
}
case 2:
{
SqlCommand lockUserCom = new SqlCommand("lockUser", myConn);
lockUserCom.CommandType = CommandType.StoredProcedure;
lockUserCom.Parameters.AddWithValue("@username", username);
lockUserCom.ExecuteNonQuery();
lbmsg.Text = "此用户名被锁,请与管理员联系!!";
uid.Text = "";
pwd.Text = "";
break;
}
}

}
myRead1.Close();
myConn.Close();
uid.Focus();
}
}
else
{
lbmsg.Text = "此用户名被锁,请与管理员联系!";
uid.Text = "";
pwd.Text = "";
myConn.Close();
}
}
}
jingsong2008 2009-04-29
  • 打赏
  • 举报
回复
如果你的TextBox是服务器端的控件,就可以直接把值从数据库中取出然后进行比较,
如果是客户端的控件,建议你用Ajax代码实现
zhanghw0704 2009-04-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 hezezcz 的回复:]
用Ajax连接数据库,把数据库的数据调出来和前台的比较!
[/Quote]
那是写个类还是 建个aspx界面啊
ajax我不会啊
hezezcz 2009-04-29
  • 打赏
  • 举报
回复
用Ajax连接数据库,把数据库的数据调出来和前台的比较!
aierda 2009-04-29
  • 打赏
  • 举报
回复
你可以用AJAX来实现,当用户名和密码正确时再转到相应的页面
mengfeihui 2009-04-29
  • 打赏
  • 举报
回复
必须在后台连接数据库,搜出数据来传到前台,可以用AJAX方法传前台

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧