zoukankan      html  css  js  c++  java
  • 登录

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    
    namespace 登录
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                string user = textBox1.Text;
                string pass = textBox2.Text;
                bool isok=checkuser(user,pass);
                if (isok)
                {
                    MessageBox.Show("登录成功");
                }
                else
                {
                    MessageBox.Show("登录失败");
                }
            }
            public bool checkuser(string user,string pass)
            {
                bool isok = false;
                //连接数据库
                SqlConnection conn = new SqlConnection("server=.;database=订购管理;user=sa;pwd=123");
                conn.Open();//打开数据库
                SqlCommand cmd = conn.CreateCommand();
                //执行语句
                cmd.CommandText = "select *from users where username='"+user+"' and  pass='"+pass+"'";
                //弹出个窗口看看语句格式是不是正确
                MessageBox.Show(cmd.CommandText);
                //遍历每一行数据,返回bool值
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    isok = true; 
                }
                conn.Close();
                return isok;
            }
        }
    }
  • 相关阅读:
    2017年5月15号课堂笔记
    2017年5月12号课堂笔记
    2017年5月8号课堂笔记
    2017年5月5号课堂笔记
    2017年4月26号课堂笔记
    不忘初心,坚持走下去
    2017年4月24号课堂笔记
    2017年4月21号课堂笔记
    2017年4月19号课堂笔记
    autoit UIA获取Listview的信息
  • 原文地址:https://www.cnblogs.com/happinesshappy/p/4542649.html
Copyright © 2011-2022 走看看