您的位置:首页 > 其它

登录

2015-05-31 20:56 393 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 登录
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string user = textBox1.Text;
string pass = textBox2.Text;
bool isok=checkuser(user,pass);
if (isok)
{
MessageBox.Show("登录成功");
}
else
{
MessageBox.Show("登录失败");
}
}
public bool checkuser(string user,string pass)
{
bool isok = false;
//连接数据库
SqlConnection conn = new SqlConnection("server=.;database=订购管理;user=sa;pwd=123");
conn.Open();//打开数据库
SqlCommand cmd = conn.CreateCommand();
//执行语句
cmd.CommandText = "select *from users where username='"+user+"' and  pass='"+pass+"'";
//弹出个窗口看看语句格式是不是正确
MessageBox.Show(cmd.CommandText);
//遍历每一行数据,返回bool值
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
isok = true;
}
conn.Close();
return isok;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: