zoukankan      html  css  js  c++  java
  • 存储过程——数据库优化方法(二)

    use Student
    create table UserLogin
    (
        UserName varchar(50) not null,
        UserPassword varchar(50) not null
    )
    alter procedure sp_Login
    @uid varchar(50),
    @pwd varchar(50),
    @result bit output
    as
    begin
      declare @count int
      set @count=(select count(*) from UserLogin where UserName=@uid and UserPassword=@pwd)
      if @count>1
        begin
         set @result=1
        end
      else
        begin
          set @result=0
        end
    end
    declare @r bit
    exec sp_Login 'ggg','ggg',@result=@r output
    print @r
    private void button1_Click(object sender, EventArgs e)
            {
                string pwd = this.textBox1.Text.Trim();
                string uid = this.textBox2.Text.Trim();
                string constr = ConfigurationManager.ConnectionStrings["sql"].ConnectionString;
                SqlConnection con = new SqlConnection(constr);
                con.Open();
                SqlCommand cmd = new SqlCommand("sp_Login",con);
                SqlParameter[] sp = new SqlParameter[]{
                  new SqlParameter("@uid",pwd),
                  new SqlParameter("pwd",uid),
                  new SqlParameter("@result",SqlDbType.Bit)
                };
                sp[2].Direction = ParameterDirection.Output;
                cmd.Parameters.AddRange(sp);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.ExecuteScalar();
                bool b = Convert.ToBoolean(sp[2].Value);
                if (b)
                {
                    MessageBox.Show("登录成功");
                }
                else
                {
                    MessageBox.Show("登录失败");
                }
    
                
            }
  • 相关阅读:
    组合算法实现
    Memcached 和 Redis 分布式锁方案
    CLR 内存分配和垃圾收集 GC
    Windbg 的使用和常用命令
    Geohash 算法学习
    经纬度计算
    Windbg 分析CPU上涨
    Windbg 分析内存上涨
    django基于存储在前端的token用户认证
    非常详细的Django使用Token(转)
  • 原文地址:https://www.cnblogs.com/772933011qq/p/4534560.html
Copyright © 2011-2022 走看看