码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET用户登录按钮事件

时间:2014-06-12 19:09:01      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   java   http   

bubuko.com,布布扣
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace HotelMIS
 7 {
 8     public static class DBHelper
 9     {
10         //连接数据库字符串
11         public static readonly string conStr = "Server=.;Database=HotelManager;Integrated security=true";
12     }
13 }
bubuko.com,布布扣
bubuko.com,布布扣
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 using Hotel.BLL;
10 using System.Data.SqlClient;
11 
12 namespace HotelMIS
13 {
14     public partial class Form1 : Form
15     {
16         public Form1()
17         {
18             InitializeComponent();
19         }
20 
21         //登录按钮事件
22         private void btnLogin_Click(object sender, EventArgs e)
23         {
24             if (textBox1.Text.Trim() == "" || string.IsNullOrEmpty(textBox1.Text))
25             {
26                 MessageBox.Show("用户名不能为空!", "登录提示");
27             }
28             else if (textBox2.Text.Trim() == "" || string.IsNullOrEmpty(textBox2.Text))
29             {
30                 MessageBox.Show("密码不能为空", "登录提示");
31             }
32             else
33             {
34                 SqlConnection con = new SqlConnection(DBHelper.conStr);
35                 try
36                 {
37                     con.Open();
38                     string sql = string.Format("select * from HotelUser where UserName = ‘{0}‘ and Password = ‘{1}‘", textBox1.Text, textBox2.Text);
39                     SqlCommand cmd = new SqlCommand(sql, con);
40                     SqlDataReader dr = cmd.ExecuteReader();
41                     if (dr.Read())
42                     {
43                         MessageBox.Show("登录成功", "登录提示");
44                     }
45                     else
46                     {
47                         MessageBox.Show("用户名或密码错误", "登录提示");
48                     }
49                     dr.Close();
50                 }
51                 catch (Exception)
52                 {
53                     MessageBox.Show("请检查连接字符串", "登录提示");
54                 }
55                 finally
56                 {
57                     con.Close();
58                 }
59             }
60         }
61     }
62 }
bubuko.com,布布扣

 

ASP.NET用户登录按钮事件,布布扣,bubuko.com

ASP.NET用户登录按钮事件

标签:style   class   blog   code   java   http   

原文地址:http://www.cnblogs.com/hellowzl/p/3781721.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!