using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace UseComplexNesting
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}
private void Frm_Main_Load(object sender, EventArgs e)
{
dgv_Message.DataSource = GetMessage();//设置数据源
}
private void btn_Select_Click(object sender, EventArgs e)
{
dgv_Message.DataSource = GetLaborage();//设置数据源
}
/// <summary>
/// 查询工资信息
/// </summary>
/// <returns>方法返回DataTable对象</returns>
private DataTable GetLaborage()
{
string P_Str_ConnectionStr = string.Format(//创建数据库连接字符串
@"server=WIN-GI7E47AND9R\LS;database=db_TomeTwo;uid=sa;pwd=");
string P_Str_SqlStr = string.Format(//创建SQL查询字符串
@"SELECT * FROM tb_EmployeeLaborage WHERE 工资月份=10 AND 人员姓名 IN(
SELECT 负责人 FROM tb_EmployeeDepartment WHERE 负责人 IN
(SELECT 人员姓名 FROM tb_EmployeePerson WHERE 学历='本科')) ORDER BY 人员编号");
SqlDataAdapter P_SqlDataAdapter = new SqlDataAdapter(//创建数据适配器
P_Str_SqlStr, P_Str_ConnectionStr);
DataTable P_dt = new DataTable();//创建数据表
P_SqlDataAdapter.Fill(P_dt);//填充数据表
return P_dt;//返回数据表
}
/// <summary>
/// 查询数据库信息
/// </summary>
/// <returns>方法返回DataTable对象</returns>
private DataTable GetMessage()
{
string P_Str_ConnectionStr = string.Format(//创建数据库连接字符串
@"server=WIN-GI7E47AND9R\LS;database=db_TomeTwo;uid=sa;pwd=");
string P_Str_SqlStr = string.Format(//创建SQL查询字符串
"select * from tb_EmployeeLaborage, tb_EmployeeDepartment");
SqlDataAdapter P_SqlDataAdapter = new SqlDataAdapter(//创建数据适配器
P_Str_SqlStr, P_Str_ConnectionStr);
DataTable P_dt = new DataTable();//创建数据表
P_SqlDataAdapter.Fill(P_dt);//填充数据表
return P_dt;//返回数据表
}
}
}