private void button1_Click(object sender, EventArgs e) { try { if (textBox1.Text == "输入工号" || textBox1.Text == "") { DataGridView data = new DataGridView(); employeedao p = new employeedao(); List <employ> rs = new List <employ>(); rs = p.find_all1(); Console.Write(rs); int i = 0; DataSet ds = new DataSet(); DataTable dt = new DataTable("Table_New"); dt.Columns.Add("工号", typeof(string)); dt.Columns.Add("姓名", typeof(string)); dt.Columns.Add("联系电话", typeof(String)); foreach (employ r1 in rs) { dt.Rows.Add(r1.Employee_number, r1.Employee_name, r1.Phone); i++; } dataGridView1.DataSource = dt; } else { DataGridView data = new DataGridView(); employeedao p = new employeedao(); employ r1 = p.selectid(textBox1.Text); Console.Write(textBox1.Text); if (r1 == null) { MessageBox.Show("不存在此人"); } else { DataSet ds = new DataSet(); DataTable dt = new DataTable("Table_New"); dt.Columns.Add("工号", typeof(string)); dt.Columns.Add("姓名", typeof(string)); dt.Columns.Add("联系电话", typeof(String)); dt.Rows.Add(r1.Employee_number, r1.Employee_name, r1.Phone); dataGridView1.DataSource = dt; } } } catch (SystemException) { MessageBox.Show("操作有误"); } }
private void employee_purchase_Load(object sender, EventArgs e) { DataGridView data = new DataGridView(); employeedao p = new employeedao(); List <employ> rs = new List <employ>(); rs = p.find_all1(); Console.Write(rs); int i = 0; DataSet ds = new DataSet(); DataTable dt = new DataTable("Table_New"); dt.Columns.Add("工号", typeof(string)); dt.Columns.Add("姓名", typeof(string)); dt.Columns.Add("联系电话", typeof(String)); foreach (employ r1 in rs) { dt.Rows.Add(r1.Employee_number, r1.Employee_name, r1.Phone); i++; } dataGridView1.DataSource = dt; }