📄 historyinfo.cs
字号:
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.OleDb;
using System.Data.SqlClient;
namespace renshiguanli
{
public partial class history : Form
{
dataClass ID=new dataClass();
public history()
{
InitializeComponent();
}
/*public history()
{
InitializeComponent();
try
{
// 初始化Form
this.Left = 0;
this.Top = 0;
this.Text = "在ListView中显示数据库内容!";
// 初始化ListView
lv = new ListView();
lv.Left = 0;
lv.Top = 0;
lv.Width =700;
lv.Height = this.ClientRectangle.Height;
lv.GridLines = true;
//file://显示各个记录的分隔线
lv.FullRowSelect = true;
//file://要选择就是一行
lv.View = View.Details;
//file://定义列表显示的方式
lv.Scrollable = true;
//file://需要时候显示滚动条
lv.MultiSelect = false; // 不可以多行选择
lv.HeaderStyle = ColumnHeaderStyle.Nonclickable;
this.Dock = DockStyle.Fill;
// 针对数据库的字段名称,建立与之适应显示表头
lv.Columns.Add("员工号码", 100, HorizontalAlignment.Right);
lv.Columns.Add("姓名", 100, HorizontalAlignment.Left);
lv.Columns.Add("department", 100, HorizontalAlignment.Left);
lv.Columns.Add("Email", 100, HorizontalAlignment.Left);
lv.Columns.Add("初步工资", 100, HorizontalAlignment.Left);
//lv.Columns.Add("初步工资", 100, HorizontalAlignment.Left);
//lv.Columns.Add("电子邮件", 100, HorizontalAlignment.Left);
lv.Visible = true;
OleDbDataReader reader;
string strCommand = "SELECT * FROM Persons";
this.conConnection.Open();// 打开数据连接
OleDbCommand cmd = new OleDbCommand(strCommand, conConnection);
reader = cmd.ExecuteReader();//获得数据集
// 不断往列表中添加数据记录
while (reader.Read())
{
ListViewItem li = new ListViewItem();
li.SubItems.Clear();
li.SubItems[0].Text = reader[3].ToString();
li.SubItems.Add(reader[4].ToString());
li.SubItems.Add(reader[1].ToString());
li.SubItems.Add(reader[2].ToString());
li.SubItems.Add(reader[5].ToString());
//li.SubItems.Add(reader[6].ToString());
//li.SubItems.Add(reader[7].ToString());
lv.Items.Add(li);
}
reader.Close();
// 关闭数据集
// 在Form中添加此列表
this.Controls.Add(lv);
// 关闭Form的时候,同时也关闭数据连接
this.Closed += new EventHandler(this_Closed);
}
catch (Exception e)
{
MessageBox.Show("连接错误!" + e.ToString(), "错误!");
}
}
protected void this_Closed(object sender, EventArgs eArgs)
{
this.conConnection.Close();//file://关闭数据连接
}
private void 确定_Click(object sender, EventArgs e)
{
this.Close();
}
private static string strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\MY.MDB";
private OleDbConnection conConnection = new OleDbConnection(strConnect);
private ListView lv;
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}*/
private void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
{
}
private void check_Click(object sender, EventArgs e)
{
this.Close();
}
private void history_Load(object sender, EventArgs e)
{
ID.historydata(dataGridView1);
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -