一、數據庫的建立
在fiber_yy數據庫下創建yy_user_record表
可以先手動填入幾條數據信息
初始數據庫信息
username為用戶賬號
sex為用戶注冊所填寫的性別
phone為用戶手機號
time為用戶登錄該系統的時間
二、頁面的設計
登錄注冊頁面我就不演示了,前幾篇博文也都有介紹
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登錄了,故會添加一條記錄
精確查找
最終的數據庫