c#.net用户登录、注册和模糊查询源代码
2010-06-13 14:30
525 查看
登陆源代码:
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("请输入用户名和密码,然后再登陆");
return;
}
string SQL = "select 类别 from 用户表 where 用户名=";
SQL += "'" + textBox1.Text + "'" + "and 密码='" + textBox2.Text + "'";
string myconstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|db1.mdb";
OleDbCommand mycom = null;
OleDbConnection mycon = null;
try
{
mycon = new OleDbConnection(myconstr);
mycon.Open();
mycom = new OleDbCommand(SQL, mycon);
OleDbDataReader rd = mycom.ExecuteReader();
if (rd.HasRows)
{
rd.Read();
this.Hide();
Form1 m = new Form1();
m.ShowDialog();
this.textBox1.Clear();
this.textBox2.Clear();
this.textBox1.Focus();
}
else
{
MessageBox.Show("没有这个用户或密码不正确,请重新登录!");
return;
}
}
catch (OleDbException oe)
{
MessageBox.Show(oe.Message, "Error");
}
finally
{
if (mycon.State == ConnectionState.Open)
mycon.Close();
}
}
注册源代码:
private void button1_Click(object sender, EventArgs e)
{
string ConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|db1.mdb;";
OleDbConnection mycon = new OleDbConnection(ConStr);
try
{
mycon.Open();
string insert = "insert into 用户表(用户名,密码,类别)values";
insert += "('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
OleDbCommand mycom = new OleDbCommand(insert,mycon);
DataSet mydata = new DataSet();
OleDbDataAdapter myadapter = new OleDbDataAdapter(mycom);
if (textBox1.Text == "" && textBox2.Text == "")
MessageBox.Show("所有项都是必填项,请填完后再单击注册按钮");
myadapter.Fill(mydata,"用户表");
MessageBox.Show("注册成功!");
//myadapter.Update(mydata, "用户表");
}
catch (OleDbException te)
{
MessageBox.Show(te.Message);
}
finally
{
if (mycon.State == ConnectionState.Open)
mycon.Close();
}
}
模糊查询源代码:
//按姓名查找
private void button1_Click(object sender, EventArgs e)
{
string ConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|db1.mdb;";
OleDbConnection Con = new OleDbConnection(ConStr);
string str = "select * from 学生表 ";
str += "where 姓名 like '%" + textBox1.Text.Trim() + "%'";
OleDbCommand Com = new OleDbCommand(str, Con);
OleDbDataAdapter myda = new OleDbDataAdapter();
myda.SelectCommand = Com;
Con.Open();
DataSet myds = new DataSet();
MessageBox.Show(str);
myda.Fill(myds, "学生表");
Con.Close();
dataGridView1.DataSource = myds;
dataGridView1.DataMember = "学生表";
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
MessageBox.Show("请输入用户名和密码,然后再登陆");
return;
}
string SQL = "select 类别 from 用户表 where 用户名=";
SQL += "'" + textBox1.Text + "'" + "and 密码='" + textBox2.Text + "'";
string myconstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|db1.mdb";
OleDbCommand mycom = null;
OleDbConnection mycon = null;
try
{
mycon = new OleDbConnection(myconstr);
mycon.Open();
mycom = new OleDbCommand(SQL, mycon);
OleDbDataReader rd = mycom.ExecuteReader();
if (rd.HasRows)
{
rd.Read();
this.Hide();
Form1 m = new Form1();
m.ShowDialog();
this.textBox1.Clear();
this.textBox2.Clear();
this.textBox1.Focus();
}
else
{
MessageBox.Show("没有这个用户或密码不正确,请重新登录!");
return;
}
}
catch (OleDbException oe)
{
MessageBox.Show(oe.Message, "Error");
}
finally
{
if (mycon.State == ConnectionState.Open)
mycon.Close();
}
}
注册源代码:
private void button1_Click(object sender, EventArgs e)
{
string ConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|db1.mdb;";
OleDbConnection mycon = new OleDbConnection(ConStr);
try
{
mycon.Open();
string insert = "insert into 用户表(用户名,密码,类别)values";
insert += "('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
OleDbCommand mycom = new OleDbCommand(insert,mycon);
DataSet mydata = new DataSet();
OleDbDataAdapter myadapter = new OleDbDataAdapter(mycom);
if (textBox1.Text == "" && textBox2.Text == "")
MessageBox.Show("所有项都是必填项,请填完后再单击注册按钮");
myadapter.Fill(mydata,"用户表");
MessageBox.Show("注册成功!");
//myadapter.Update(mydata, "用户表");
}
catch (OleDbException te)
{
MessageBox.Show(te.Message);
}
finally
{
if (mycon.State == ConnectionState.Open)
mycon.Close();
}
}
模糊查询源代码:
//按姓名查找
private void button1_Click(object sender, EventArgs e)
{
string ConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|db1.mdb;";
OleDbConnection Con = new OleDbConnection(ConStr);
string str = "select * from 学生表 ";
str += "where 姓名 like '%" + textBox1.Text.Trim() + "%'";
OleDbCommand Com = new OleDbCommand(str, Con);
OleDbDataAdapter myda = new OleDbDataAdapter();
myda.SelectCommand = Com;
Con.Open();
DataSet myds = new DataSet();
MessageBox.Show(str);
myda.Fill(myds, "学生表");
Con.Close();
dataGridView1.DataSource = myds;
dataGridView1.DataMember = "学生表";
}
相关文章推荐
- c#.net用户登录、注册和模糊查询源代码
- 注册登录系统的基本逻辑与结构——ASP.NET(C#)源代码
- 注册登录系统的基本逻辑与结构——ASP.NET(C#)源代码
- vs2010asp.net网站制作用户注册登录界面源代码(包含验证码)并把用户信息保存到数据库sql2008
- C# B/S程序中出现“异常详细信息: System.Data.SqlClient.SqlException: 用户 'XXX/ASPNET' 登录失败。”的处理方法
- ASP.NET C# 连接SQL SERVER数据库 实现用户注册页面
- Jquery如何序列化form表单数据为JSON对象 C# ADO.NET中设置Like模糊查询的参数 从客户端出现小于等于公式符号引发检测到有潜在危险的Request.Form 值 jquery调用iframe里面的方法 Js根据Ip地址自动判断是哪个城市 【我们一起写框架】MVVM的WPF框架(三)—数据控件 设计模式之简单工厂模式(C#语言描述)
- PHP 开发API接口 注册,登录,查询用户资料
- php开发 API接口注册,登录,查询用户资料
- Unity C# 连接SQL Server数据库,实现获取和添加登录注册的用户列表
- MD5算法原理简要介绍并采用C#应用在桌面应用系统的用户登录与注册中
- C# MVC 用户登录状态判断 【C#】list 去重(转载) js 日期格式转换(转载) C#日期转换(转载) Nullable<System.DateTime>日期格式转换 (转载) Asp.Net MVC中Action跳转(转载)
- asp.net 实现用户登录和注册——基于webform模式
- asp.net中用户注册、角色分配,以及已登录用户的退出
- C# 餐桌项目增加、修改、删除、查询(登录注册界面)
- 写了一个Windows服务,通过C#模拟网站用户登录并爬取BUG列表查询有没有新的BUG,并提醒我
- C#.net 制作用户登录并连接数据库跳转页面
- C#_ADO.NET验证用户登录
- Owin+ASP.NET Identity浅析系列(一)用户登录注册