您的位置:首页 > 数据库

用asp.net连接数据库的登陆代码

2015-12-25 19:08 495 查看
用asp.net连接数据库,做登录页面,怎么弄呢?

办法:
using System.Data.SqlClient;//记得加引用
private bool Login(string sno,string sname)
{
SqlConnection con = new SqlConnection("Data Source=数据库连接;Initial Catalog=Stu_table;User ID=sa;Password=123456789");
con.Open();
string sql = string.Format("select count(*) from Student where Sno='{0}' and Sname='{1}'",sno,sname);//这里你自己改改了,不知道你用什么登陆的,账号密码不知道你用什么字段,暂时认为你用学号跟姓名登陆
SqlCommand com = new SqlCommand(sql, con);
int flag =(int) com.ExecuteScalar();
con.Close();
if (flag > 0)
{
return true;
}
return false;
}


//把上面的代码放在login.aspx.cs里面,你哪里登陆就调用这个函数,传登陆账号跟密码进来就行了.

//登陆成功就返回true,否则就返回false

//登陆成功你可以用下列语句跳转到你那个页面

Response.Redirect("里面你跳转的Url");

//登陆失败你可以提示 

Response.Write("<script> alert('账号密码错误');</script>");

//上面这个逻辑自己写不出来的,那就真没办法了,小孩子都会了

//数据库连接:这个你自己改,一般用 . 表示,你也可以自己开你的数据库看。

问题:怎么实现鼠标跟随事件与滚动条的绑定?

鼠标跟随事件在给了body高度之后,想要跟随的图片到一定位置之后就不在变化了,是为什么?

代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>广告</title>
</head>
<body style="height:1500px">
<script type="text/javascript">
function badAD(html){
var gg=document.body.appendChild(document.createElement('div'));
gg.style.cssText="border:1px solid pink;background:#000;position:absolute;";
gg.innerHTML=html||'This is bad idea!';
var c=gg.appendChild(document.createElement('span'));
c.innerHTML="×";
c.style.cssText="position:absolute;right:4px;top:15px;cursor:pointer;color:red;font-weight:bold;";
c.onclick=function (){
document.onmousemove=null;
this.parentNode.style.left='-99999px'
};
document.onmousemove=function (e){
e=e||window.event;
var x=e.clientX,y=e.clientY;
setTimeout(function() {
if(gg.hover)return;
gg.style.left=x+5+'px';
gg.style.top=y+5+'px';
},120)
}
gg.onmouseover=function (){
this.hover=true
};
gg.onmouseout=function (){
this.hover=false
}
}
badAD('"一个链接"; "><img src="4.png"></a>')
</script>
</body>
</html>


回答:

看这里:var x=e.pageX,y=e.pageY;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息