在C#中登陆按钮代码

在C#中登陆按钮代码:

private   void  button1_Click( object  sender, System.EventArgs e) 
  { 
   
switch (comboBox1.SelectedIndex) 
   { 
    
case   0
     
if (textBox1.Text == "" || textBox2.Text == ""
     { 
      MessageBox.Show(
" 用户名和密码不能为空 " , " 提示 " ,MessageBoxButtons.RetryCancel,MessageBoxIcon.Information); 
      
return
     } 
     
else  
     { 
      
try  
      { 
       OleDbConnection conn
= db.createdb(); 
       conn.Open(); 
       OleDbCommand cmd
= new  OleDbCommand( " select count(*) from user_info where user_id=' " + textBox1.Text + " 'and user_pwd=' " + textBox2.Text + " 'and beizhu='1' " ,conn); 
       
int  count = Convert.ToInt32(cmd.ExecuteScalar().ToString()); 
       
if (count > 0
       { 
        Form2 form
= new  Form2(); 
        form.Show(); 
        
this .Hide(); 

       } 
      } 
      
catch (Exception ex) 
      { 
       MessageBox.Show(
" 错误 " + ex.ToString(), " 错误 " ); 
      } 
      
     } 
     
break
default
break

   } 

登陆: 

public   class  Users 

   
private   string  username = ""
   
private   string  password = ""
   
public   string  UserName 
   { 
      
get { return   this .username;} 
      
set { this .username = value;} 
   } 
   
public   string  Password 
   { 
      
get { return   this .password;} 
      
set { this .password = value;} 
   } 
   
public   string  CheckUser() 
   { 
      SqlConnection con
= new  SqlConnection(ConfigurationSettings.AppSettings[ " ConStr " ]); 
      SqlCommand cmd
= new  SqlCommand(); 
      cmd.Connection
= con; 
      cmd.CommandText
= " select UserName,Password from Users where UserName=@uname "
      cmd.Parameters.Add(
" @uname " ,SqlDbType.VarChar, 10 ); 
      cmd.Parameters[
0 ].Value = UserName; 
      
string  pass = ""
      
try  
      { 
         con.Open(); 
         SqlDataReader reader
= cmd.ExecuteReader(); 
         
if (reader.Read()) 
         { 
             pass
= reader[ 1 ].ToString(); 
         } 
         
else  
         { 
             reader.Close(); 
             con.Close(); 
             
return  UserName + " 用户存在! "
          } 
          reader.Close(); 
          con.Close(); 
      } 
      
catch (SqlException er) 
      { 
          
if (con.State == ConnectionState.Open) 
               con.Close(); 
          
return  er.Message; 
      } 
      
if (pass.Trim() != Password.Trim()) 
      { 
          
return   " 对不起! " + UserName + " 用户密码不正确! "
      } 

      
return   " OK "
   } 
}

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值