• 实验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();
    	        }
    	    }
    	}
    
    
  • 相关阅读:
    实例代码讲解_Person
    推荐一个小工具:LINQ to JavaScript (jslinq)
    AJAX跨域问题解决一:使用web代理
    JQuery常用方法总结(2)
    对IEnumerable<T>,IDictionary<Tkey,TValue>,ICollection<T>,IList<T>的总结
    C#补零
    JQuery常用方法总结(1)
    单一模式(Singleton)的学习
    .net core 和 WPF 开发升讯威在线客服系统:调用百度翻译接口实现实时自动翻译
    在“宝塔”中部署升讯威在线客服系统教程来了,只需10分钟,确实方便!
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13285163.html
Copyright © 2020-2023  润新知