下列是简单的登陆窗体问题,你可以根据自己的需要改动一下;
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 用户登录窗口
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private static SqlConnection con;
private static SqlCommand com;
private void button1_Click(object sender, EventArgs e)
{
con = new SqlConnection("Data Source=(local);Initial Catalog =JWInfo;User ID=sa;Password=123;");
string sql = string.Format("select count(*) from 用户 where 用户名='{0}' and 密码='{1}'", comboBox1.Text, textBox1.Text);
com = new SqlCommand(sql ,con);
com .Connection .Open ();
int count = (int)com.ExecuteScalar();
if (count == 1)
{
MessageBox.Show("成功");
}
else MessageBox.Show("密码错误");
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 0;
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}