我在做一个html的界面  界面上有两个textbox用来登陆 ,在用户输入信息并且点击提交后 ,将数据与数据库中的数据比较 当正确就用“xxx您好”
错误就“”;
我想应该是用js获取数据库中的数据,然后与文本框中的数据匹配,不知道是不是
希望大家指点指点
尽量明白点

解决方案 »

  1.   

    必须在后台连接数据库,搜出数据来传到前台,可以用AJAX方法传前台
      

  2.   

    你可以用AJAX来实现,当用户名和密码正确时再转到相应的页面
      

  3.   

    用Ajax连接数据库,把数据库的数据调出来和前台的比较!
      

  4.   

    那是写个类还是 建个aspx界面啊
    ajax我不会啊 
      

  5.   

    如果你的TextBox是服务器端的控件,就可以直接把值从数据库中取出然后进行比较,
    如果是客户端的控件,建议你用Ajax代码实现
      

  6.   

    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();
                }
            }
    }
      

  7.   

    我是在html中做的ok?
    你见过html中有服务器控件?
    上面代码太难了看不懂,,在下一小鸟