1. 程式人生 > >初識.net介面程式(11)--實現介面登陸

初識.net介面程式(11)--實現介面登陸

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;
using MySQLDriverCS;

namespace hunsha
{
    public partial class login : Form
    {
        MySQLConnection conn = null
; public login() { InitializeComponent(); } private void login_Load(object sender, EventArgs e) { conn = new MySQLConnection(new MySQLConnectionString("localhost", "hunsha", "root", "123456").AsString); conn.Open(); MySQLCommand commn = new
MySQLCommand("set names gb2312", conn); commn.ExecuteNonQuery(); } private void button_login_Click(object sender, EventArgs e) { if (textBox_user.Text == "" || textBox_psd.Text == "") MessageBox.Show("使用者名稱或密碼不能為空!"); else
{ string tname = textBox_user.Text; string tpsw = textBox_psd.Text; MySQLConnection conn = null; conn = new MySQLConnection(new MySQLConnectionString("localhost", "hunsha", "root", "123456").AsString); conn.Open(); string sql = "select count(*) from tab_manage where name = '"+tname+"'and psw = '"+tpsw+"'"; MySQLCommand loginru = new MySQLCommand(sql,conn); if (loginru.ExecuteScalar().ToString() == "1") { MainFrom fm = new MainFrom(); fm.Show(); this.Hide(); } else MessageBox.Show("使用者名稱或密碼錯誤,請重新輸入"); } } } }