如何C#中一个窗体里两个dataGridView分别连接两个表
在C#中一个窗体里我又两个dataGridView(dataGridViewEmp,dataGridViewdepart),想分别分别连接到数据可中的两个表Employe...
在C#中一个窗体里我又两个dataGridView(dataGridViewEmp,dataGridViewdepart),想分别分别连接到数据可中的两个表Employee和Department中
如何做到,请高手指点……
感激不尽……
conn = new SqlConnection("Integrated Security=SSPI;DataBase=LEDLEE;Server=.");
SqlCommand cmd = new SqlCommand("Select Employee.EmployeeID'员工号',Name'姓名',Sex'性别',Birthday'出生时间',People'民族',Address'家庭住址',PhoneNumber'电话',Email'邮箱',DepartmentName'部门',Income'工资',Outcome'花费',Note1'个人备注' from Employee,Department,Salary where Employee.EmployeeID=Salary.EmployeeID and Employee.DepartmentID=Department.DepartmentID;Select DepartmentID'部门号',DepartmentName'部门',Note2'部门备注' from Department;", conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridViewEmp.DataSource = ds.Tables[0];
dataGridViewDepart.DataSource = ds.Tables[1];
这样就行了! 展开
如何做到,请高手指点……
感激不尽……
conn = new SqlConnection("Integrated Security=SSPI;DataBase=LEDLEE;Server=.");
SqlCommand cmd = new SqlCommand("Select Employee.EmployeeID'员工号',Name'姓名',Sex'性别',Birthday'出生时间',People'民族',Address'家庭住址',PhoneNumber'电话',Email'邮箱',DepartmentName'部门',Income'工资',Outcome'花费',Note1'个人备注' from Employee,Department,Salary where Employee.EmployeeID=Salary.EmployeeID and Employee.DepartmentID=Department.DepartmentID;Select DepartmentID'部门号',DepartmentName'部门',Note2'部门备注' from Department;", conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridViewEmp.DataSource = ds.Tables[0];
dataGridViewDepart.DataSource = ds.Tables[1];
这样就行了! 展开
展开全部
用歼散宽氏亮掘裤dataset绑定也可以
OracleConnection con = new OracleConnection();
OracleDataAdapter adptOrd;
DataSet dsOrd = new DataSet();
OracleCommandBuilder cmdOrd;
adptOrdShp = new OracleDataAdapter("sql语句", con);
cmdOrdShp = new OracleCommandBuilder(adptOrdShp);
adptOrdShp.Fill(dsOrdShp);
dgvSHP.DataSource = dsOrdShp.Tables[0].DefaultView;
OracleConnection con = new OracleConnection();
OracleDataAdapter adptOrd;
DataSet dsOrd = new DataSet();
OracleCommandBuilder cmdOrd;
adptOrdShp = new OracleDataAdapter("sql语句", con);
cmdOrdShp = new OracleCommandBuilder(adptOrdShp);
adptOrdShp.Fill(dsOrdShp);
dgvSHP.DataSource = dsOrdShp.Tables[0].DefaultView;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
那你就创建两个DataSet,分别绑定到两个dataGridView就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个建立数据源啊,绑定不同的数据库的表,你不会没学过吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询