• 实验2 登录系统


    
    using System;
    	using System.Collections.Generic;
    	using System.ComponentModel;
    	using System.Data;
    	using System.Data.SqlClient;
    	using System.Drawing;
    	using System.Linq;
    	using System.Text;
    	using System.Threading.Tasks;
    	using System.Windows.Forms;
    	
    	namespace LoginDemo
    	{
    	    public partial class Form1 : Form
    	    {
    	        public Form1()
    	        {
    	            InitializeComponent();
    	        }
    	
    	        private void label2_Click(object sender, EventArgs e)
    	        {
    	
    	        }
    	
    	        private void textBox2_TextChanged(object sender, EventArgs e)
    	        {
    	
    	        }
    	
    	        private void button1_Click(object sender, EventArgs e)
    	        {
    	            string username = textBoxUserName.Text.Trim();  
    	            string password = textBoxPassWord.Text.Trim();  
    	
    	            //string connstr = ConfigurationManager.ConnectionStrings["connectionString"].ToString();
    	            string myConnString = "Data Source=.;Initial Catalog=Test;Persist Security Info=True;User ID=sa;Password=luoluoluo";
    	
    	            SqlConnection sqlConnection = new SqlConnection(myConnString); 
    	            sqlConnection.Open();
    	
    	            string sql = "select userid,password from usertable where userid = '" + username + "' and password = '" + password + "'";                                          
    	            SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
    	
    	            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
    	
    	            if (sqlDataReader.HasRows)
    	            {
    	                MessageBox.Show("SUCESS!", "notice", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);       
    	                label1.Text = "Log in :" + username;
    	                
    	                FormMain formMain = new FormMain(); 
    	                formMain.Show();
    	                this.Hide();  
    	            }
    	            else
    	            {
    	                MessageBox.Show("FAILED!", "notice", MessageBoxButtons.OK, MessageBoxIcon.Error);
    	            }
    	            sqlConnection.Close();
    	
    	        }
    	
    	        private void textBox1_TextChanged(object sender, EventArgs e)
    	        {
    	
    	        }
    	
    	        private void button2_Click(object sender, EventArgs e)
    	        {
    	            Application.Exit();
    	        }
    	
    	        private void Form1_Load(object sender, EventArgs e)
    	        {
    	
    	        }
    	    }
    	}
    
    	using System;
    	using System.Collections.Generic;
    	using System.ComponentModel;
    	using System.Data;
    	using System.Drawing;
    	using System.Linq;
    	using System.Text;
    	using System.Threading.Tasks;
    	using System.Windows.Forms;
    	
    	namespace LoginDemo
    	{
    	    public partial class FormMain : Form
    	    {
    	        public FormMain()
    	        {
    	            InitializeComponent();
    	        }
    	
    	        private void FormMain_Load(object sender, EventArgs e)
    	        {
    
    	            this.usertableTableAdapter.Fill(this.testDataSet.usertable);
    	
    	        }
    	
    	        private void button1_Click(object sender, EventArgs e)
    	        {
    	            Application.Exit();
    	        }
    	    }
    	}
    
    
  • 相关阅读:
    树、森林和二叉树的转换
    弱校ACM奋斗史
    安徽科技学院2016-2017-1学期2013信息与计算科学12班期末测试_题解
    安徽省2016“京胜杯”程序设计大赛_K_纸上谈兵
    安徽省2016“京胜杯”程序设计大赛_J_YZK的大别墅
    安徽省2016“京胜杯”程序设计大赛_I_恶魔A+B
    安徽省2016“京胜杯”程序设计大赛_H_单身晚会
    安徽省2016“京胜杯”程序设计大赛_G_木条染色
    安徽省2016“京胜杯”程序设计大赛_F_吃在工大
    LeetCode() Merge Intervals 还是有问题,留待,脑袋疼。
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13285163.html
Copyright © 2020-2023  润新知