1. 程式人生 > >用asp.net連線資料庫的登陸程式碼

用asp.net連線資料庫的登陸程式碼

用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;