1. 程式人生 > >筆記(登錄程序)

筆記(登錄程序)

for user from name password guanl nta new cti

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace baoxianguanli
{
public partial class login : Form
{
public login()
{
InitializeComponent();
}

private void button_login_Click(object sender, EventArgs e)
{
if (txtUserName.Text.Trim() == " " || txtUserName.Text.Trim() == " ")
{
MessageBox.Show("用戶名或密碼不能為空");
txtUserName.Focus();
return;
}
string connString = @"Data Source=(local);Initial Catalog=date1; uid=sa;pwd=123";
string sqlstr = string.Format("select count(*) from [User] where UserName=‘{0}‘ and Password=‘{1}‘",txtUserName.Text.Trim(),txtUserPassword.Text.Trim());
using (SqlConnection conn =new SqlConnection(connString))
{
SqlCommand cmd =new SqlCommand(sqlstr, conn);
conn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
MessageBox.Show("登陸成功" );

}
else
{
MessageBox.Show("用戶名或密碼錯誤,請重新輸入!","錯誤");
txtUserName.Text= " ";
txtUserPassword.Text = " ";
txtUserName.Focus ();
}
}
}

private void txtUserPassword_TextChanged(object sender, EventArgs e)
{

}
}
}

筆記(登錄程序)