一、数据库的建立
在fiber_yy数据库下创建yy_user_record表
可以先手动填入几条数据信息
初始数据库信息
二、页面的设计
登录注册页面我就不演示了,前几篇博文也都有介绍
flow_query流水查询页面
三、代码实现
flow_query流水查询页面
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
namespace fiber_yy
{
public partial class flow_query : Form
{
private DataSet dsall;
public string constr = "server=CY-20190824RMES;Initial Catalog=fiber_yy;User ID=sa;pwd=beyond";
private SqlDataAdapter mDataAdapter;
public flow_query()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(constr);
conn = new SqlConnection(constr);
mDataAdapter = new SqlDataAdapter("SELECT username AS '用户',sex AS '性别',phone AS '手机号',time AS '登录时间' FROM yy_user_record", conn);
dsall = new DataSet();
mDataAdapter.Fill(dsall, "hard");
MessageBox.Show(dsall.ToString());
dataGridView1.DataSource = dsall.Tables["hard"];
}
catch
{
MessageBox.Show("读取失败");
}
}
private void button2_Click(object sender, EventArgs e)
{
string account = textBox1.Text;
try
{
SqlConnection conn = new SqlConnection(constr);
conn = new SqlConnection(constr);
//mDataAdapter = new SqlDataAdapter("SELECT username AS '用户',sex AS '性别',phone AS '手机号',time AS '登录时间' FROM yy_user_record WHERE username='" + account + "'", conn);
mDataAdapter = new SqlDataAdapter("SELECT username AS '用户',sex AS '性别',phone AS '手机号',time AS '登录时间' FROM yy_user_record WHERE username='" + account + "'", conn);
dsall = new DataSet();
mDataAdapter.Fill(dsall, "hard");
dataGridView1.DataSource = dsall.Tables["hard"];
}
catch
{
MessageBox.Show("读取失败");
}
}
}
}
四、效果演示
程序运行
注册我就不演示了,请参考前几篇博文
从yy_user表中找个账号密码,直接用户登录
用户一旦成功登录系统,会记录时间和用户信息
登录成功
进入系统
演示流水查询
查询所有用户登录信息
这里是6条记录,原始数据库5条,因为beyond登录了,故会添加一条记录
精确查找
最终的数据库