01.
namespace
Project
02.
{
03.
public
partial
class
Form5 : Form
04.
{
05.
public
Form5()
06.
{
07.
InitializeComponent();
08.
}
09.
10.
private
void
button1_Click(
object
sender, EventArgs e)
11.
{
12.
string
path =
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/tonton/Documents/Visual Studio 2010/Projects/Project/Database1.accdb"
;
13.
OleDbConnection Con =
new
OleDbConnection(path);
14.
Con.Open();
15.
16.
string
find =
"SELECT * FROM personnel WHERE perID Like '"
+
"%"
+ textBox1.Text +
"%"
;
17.
OleDbDataAdapter D =
new
OleDbDataAdapter(find, Con);
18.
DataTable T =
new
DataTable();
19.
D.Fill(T);
20.
dataGridView1.DataSource = T;
21.
}
22.
23.
private
void
dataGridView1_CellContentClick(
object
sender, DataGridViewCellEventArgs e)
24.
{
25.
26.
if
(e.RowIndex < 0)
27.
{
return
; }
28.
textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
29.
textBox2.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
30.
textBox3.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
31.
textBox4.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
32.
textBox5.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
33.
textBox6.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
34.
textBox7.Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
35.
textBox8.Text = dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString();
36.
37.
}
38.
39.
40.
41.
private
void
Form5_Load(
object
sender, EventArgs e)
42.
{
43.
string
path =
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/tonton/Documents/Visual Studio 2010/Projects/Project/Database1.accdb"
;
44.
OleDbConnection Con =
new
OleDbConnection(path);
45.
Con.Open();
46.
47.
string
sql =
"SELECT * FROM personnel"
;
48.
49.
OleDbDataAdapter D =
new
OleDbDataAdapter(sql, Con);
50.
DataTable T =
new
DataTable();
51.
D.Fill(T);
52.
dataGridView1.DataSource = T;
53.
Con.Close();
54.
}
55.
}
56.
}