求一段连接数据库的登录代码 在ASP.NET中加了一个按扭,点击按钮,当用户名、密码正确时就可进入系统.最好是用C#编写的.请大家帮帮忙! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ADO.Net从数据库获取数据的方式:http://blog.csdn.net/chengking/archive/2005/10/07/496656.aspx 连接的是SQL SERVER 本地数据库 用 SqlDataReader吧,判断是从数据库查找的数据是否与edit中的相同就行了简单举个例子:qlConnection myconn=new SqlConnection("....");string myselect="select.....";SqlCommand mycommand=new SqlCommand(myselect,myconn);myconn.Open();SqlDataReader mydatareader;mydatareader=mycommand.ExecuteReader();然后设置一个布尔类型的变量当mydatareader.GetString().Trim()=“你的edit中的值”时返回真,否则返回false最后就是利用这个变量来判断是允许登陆还是拒绝登陆了~~~~~ private void btnlogin_Click(object sender, System.EventArgs e) { EmpDB AloginUsr=new EmpDB(); String strLoginID= username.Text .Trim (); String strPassword =password.Text .Trim (); string strReason; string strUserID; string strValid; string[] NewLogin; String[] strLoginflag =AloginUsr.Login (strLoginID,strPassword); if(strLoginflag[0]=="usererror"||strLoginflag[0]=="pwderror"||strLoginflag[0]=="noacount") { strUserID = username.Text .Trim (); strValid= "否"; strReason=strLoginflag[1]; NewLogin=new string [] { strUserID, DateTime.Now .ToString (), strValid, "", Request.UserHostAddress .ToString (), strReason }; DbManagerLogininfo myclassfologin=new DbManagerLogininfo (); myclassfologin.insertLoginUser (NewLogin); Response.Write("<script language=javascript>"); Response.Write("window.alert('"); Response.Write(strReason); Response.Write("');"); Response.Write("</script>"); } else { Response.Cookies["empint"].Value=username.Text; Response.Cookies["empint"].Expires=DateTime.Now.AddDays(1); strUserID=username.Text .Trim (); strValid="是"; strReason=""; strReason=strLoginflag[1]; NewLogin=new string [] { strUserID, DateTime.Now .ToString (), strValid, "", Request.UserHostAddress .ToString (), strReason }; DbManagerLogininfo myclassfologin=new DbManagerLogininfo (); myclassfologin.insertLoginUser (NewLogin); Session["EmpID"]=Int32.Parse(strLoginflag[0]); Session["username"]=username.Text; string tt="qminoa = window.open('"+Request.ApplicationPath+"/index.aspx"+"'" +",'','toolbar=no,menubar=no,titlebar=yes,directories=no,resizable=yes,status=yes,fullscreen=no,top=0;left=0,width=900,height=700');"; Response.Write("<script language=javascript>"); Response.Write(tt); Response.Write("qminoa.moveTo(0,0);"); Response.Write("qminoa.resizeTo(screen.availWidth,screen.availHeight);"); Response.Write("window.opener=null;"); Response.Write("window.close();"); Response.Write("</script>"); } } VS2008里面的分页问题 关于reportviewer放在有母板页的页面中问题~ ckeditor如何在后台获取焦点? VS 2008 AJAX Extensions不能用? 多功能的支持在线播放的控件 数据库bat文件怎么打开或使用? AJAX如何读取数据库数据里的图片地址并显示到页面上?我都搞了好几天了。 Response.write的变量传递问题 请问各位大侠,我想弄个视频会议,怎么解决。 Nhibernite中不想map实体中的某个字段 安装VS 2005 时提示要安装 SP1, 下载了一个中文版又提示密钥不对,怎么办? 在页面中引用JS文件,JS文件中不支持中文码?有知道的码?
http://blog.csdn.net/chengking/archive/2005/10/07/496656.aspx
简单举个例子:
qlConnection myconn=new SqlConnection("....");
string myselect="select.....";
SqlCommand mycommand=new SqlCommand(myselect,myconn);
myconn.Open();
SqlDataReader mydatareader;
mydatareader=mycommand.ExecuteReader();
然后设置一个布尔类型的变量
当mydatareader.GetString().Trim()=“你的edit中的值”时返回真,
否则返回false
最后就是利用这个变量来判断是允许登陆还是拒绝登陆了~~~~~
{
EmpDB AloginUsr=new EmpDB();
String strLoginID= username.Text .Trim ();
String strPassword =password.Text .Trim ();
string strReason;
string strUserID;
string strValid;
string[] NewLogin;
String[] strLoginflag =AloginUsr.Login (strLoginID,strPassword); if(strLoginflag[0]=="usererror"||strLoginflag[0]=="pwderror"||strLoginflag[0]=="noacount")
{
strUserID = username.Text .Trim ();
strValid= "否";
strReason=strLoginflag[1];
NewLogin=new string []
{
strUserID,
DateTime.Now .ToString (),
strValid,
"",
Request.UserHostAddress .ToString (),
strReason
};
DbManagerLogininfo myclassfologin=new DbManagerLogininfo ();
myclassfologin.insertLoginUser (NewLogin);
Response.Write("<script language=javascript>");
Response.Write("window.alert('");
Response.Write(strReason);
Response.Write("');");
Response.Write("</script>");
}
else
{
Response.Cookies["empint"].Value=username.Text;
Response.Cookies["empint"].Expires=DateTime.Now.AddDays(1); strUserID=username.Text .Trim ();
strValid="是";
strReason="";
strReason=strLoginflag[1];
NewLogin=new string []
{
strUserID,
DateTime.Now .ToString (),
strValid,
"",
Request.UserHostAddress .ToString (),
strReason
};
DbManagerLogininfo myclassfologin=new DbManagerLogininfo ();
myclassfologin.insertLoginUser (NewLogin);
Session["EmpID"]=Int32.Parse(strLoginflag[0]);
Session["username"]=username.Text;
string tt="qminoa = window.open('"+Request.ApplicationPath+"/index.aspx"+"'"
+",'','toolbar=no,menubar=no,titlebar=yes,directories=no,resizable=yes,status=yes,fullscreen=no,top=0;left=0,width=900,height=700');";
Response.Write("<script language=javascript>");
Response.Write(tt);
Response.Write("qminoa.moveTo(0,0);");
Response.Write("qminoa.resizeTo(screen.availWidth,screen.availHeight);");
Response.Write("window.opener=null;");
Response.Write("window.close();");
Response.Write("</script>");
}
}