您的位置:首页 > 编程语言 > C#

登录退出窗口

2013-09-25 22:03 197 查看
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 学生信息系统
{
//int flag=0;
public partial class Form1 : Form
{
SqlConnection p;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
SqlCommand s;
s = new SqlCommand();
s.Connection = p;
string str = "Select * from 用户表 where 用户ID='"+textBox1.Text+"'  and 用户密码='"+textBox2.Text+"'";
s.CommandText= str;
s.CommandType = CommandType.Text;
SqlDataReader sdr=s.ExecuteReader();
sdr.Read();
if(sdr.HasRows)
{
MessageBox.Show("登录成功!");
主窗体 p1 = new 主窗体();
p1.setflag(sdr[2].ToString());
p1.Show();

}
else
{
MessageBox.Show("用户名与密码不匹配!");
}
}

private void button2_Click(object sender, EventArgs e)
{
this.Close();
}

private void Form1_Load(object sender, EventArgs e)
{
p = new SqlConnection("server='(local)';database='学生信息数据库';uid='用户名';pwd='密码'");
p.Open();
if (p.State == ConnectionState.Open)
{
label3.Text = "数据库连接成功!!";
}
else
{
label3.Text = "数据库连接失败!!";
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  登录 退出 c#