登录
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; } } }
相关文章推荐
- sqlite3使用简介
- 搬家了
- 缓存之Memcached
- Android---51---加入多线程进行Socket通信
- x86_64汇编基础
- JavaScript 开发的45个经典技巧
- 在Winform中调用Dos命令
- Mandriva CEO称雇员诉讼迫使公司宣布破产
- Volley 源码解析
- 第十二周项目三-日期时间类
- 查找和替换
- May
- [Linux]grep删除空行
- Linux操作系统上用数据泵导库
- 大白话系列之C#委托与事件讲解(二)
- m进制转为n进制(0<m,n<=10)
- 第十二周项目二--摩托车继承自行车和机动车
- 构建之法之软件工程
- 使用HIGHCHARTS绘制服务端返回数据曲线图
- 关于51单片机电子时钟精度的问题