.net 入门一些常见的东西

类别:Asp 点击:0 评论:0 推荐:
  //根据用户名和口令核查

        private int CheckUserAndPwd(string usercode, string userpwd)

        {

            SqlConnection objConn = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);

            objConn.Open();

 

            //调用usp_CheckUserLogin

            SqlCommand objComm = new SqlCommand("usp_CheckUserLogin", objConn);

            objComm.CommandType = CommandType.StoredProcedure;

 

            //添加usp参数

            objComm.Parameters.Add(new SqlParameter("@usercode", usercode));

            objComm.Parameters.Add(new SqlParameter("@pwd", userpwd));

 

            //接收usp返回值

            objComm.Parameters.Add(new SqlParameter("retvalue", SqlDbType.Int, 4, ParameterDirection.ReturnValue,

                                   false, 0, 0, string.Empty, DataRowVersion.Default, null));

 

            objComm.ExecuteNonQuery();

 

            int uspReturnValue = (int)objComm.Parameters["retvalue"].Value;

 

            objConn.Close();

 

            return uspReturnValue;

        }

 

        //登陆处理

        private void Login_Click(object sender, System.Web.UI.ImageClickEventArgs e)

        {

            int uspReturnValue = CheckUserAndPwd(usercode.Text, password.Text);

 

            if(uspReturnValue == -1)

            {

                Response.Write(@"<script language=javascript>alert('该用户不存在,请先注册!');</script>");

                usercode.Text = string.Empty;

 

                Session["usercode"] = string.Empty;

            }

            else if(uspReturnValue == -2)

            {

                Response.Write(@"<script language=javascript>alert('该用户对应口令有误!');</script>");

                password.Text = string.Empty;

 

                Session["usercode"] = string.Empty;

            }

            else if(uspReturnValue == 0)

            {

                Response.Write(@"<script language=javascript>alert('登陆成功!');</script>");

 

                Session["usercode"] = usercode.Text;

 

                //更新用户最后登陆时间

                UpdateUserAccessDT(usercode.Text);

 

                usercode.Text = string.Empty;

                password.Text = string.Empty;

            }

        }


private void fill()//datagrid与后台数据库绑定

  {
   string connString="server=(local);database=table;uid=sa;pwd=;";
   //string sql="select *,year(getdate())-year(jb_2) as hh from ta1";
   SqlConnection conn=new SqlConnection(connString);
   SqlCommand cmd=new SqlCommand("show_waitlist",conn);
   cmd.CommandType=CommandType.StoredProcedure;
   DataSet objDataSet = new DataSet();
   SqlDataAdapter objDA = new SqlDataAdapter();

   objDA.SelectCommand = cmd;
   objDA.Fill(objDataSet, "DataGrid1");//数据添充
   DataGrid1.DataSource=objDataSet.Tables["DataGrid1"].DefaultView;//数据源
   DataGrid1.DataBind();//数据绑定
  }

本文地址:http://com.8s8s.com/it/it7820.htm