private void button5_Click(object sender, System.EventArgs e)
{
this.oleDbDataAdapter1 .Fill(df31);
this.oleDbDataAdapter2 .Fill (df31);
DataColumn mastercl;
DataColumn childcl;
mastercl=this.df31 .Tables ["bom_pcs"].Columns ["bom_pcs"];
childcl=this.df31 .Tables ["bom_pcs_sub"].Columns ["bom_pcs"];
DataRelation bom_pcsrel;
bom_pcsrel = new DataRelation ("vdfsg",mastercl,childcl);
df31.Relations .Add (bom_pcsrel);
this.dataGrid1 .DataSource =df31.bom_pcs_sub ;
}
this.dataGrid1.SetDataBinding(this.ds,"customers");
this.dataGrid2.SetDataBinding
(this.ds,"customers.CustomerToContacts");
reference:
ms-
help://MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/vbcon/html/vbts
kcreatingmasterdetailslistwithdatagrid.htm
还有个问题我在移动记录时是否只移动父表记录就可以了?
"derek" <dere...@163.net> 写入消息新闻
:0b1e01c366dc$d32966d0$a101...@phx.gbl...
改为这样:
private void button5_Click(object sender, System.EventArgs e)
{
this.oleDbDataAdapter1 .Fill(df31);
this.oleDbDataAdapter2 .Fill (df31);
DataColumn mastercl;
DataColumn childcl;
mastercl=this.df31 .Tables ["bom_pcs"].Columns ["bom_pcs"];
childcl=this.df31 .Tables ["bom_pcs_sub"].Columns ["bom_pcs"];
DataRelation bom_pcsrel;
bom_pcsrel = new DataRelation ("vdfsg",mastercl,childcl);
df31.Relations .Add (bom_pcsrel);
//this.dataGrid1 .DataSource =df31.bom_pcs_sub ;
//这里加上指定datagrid1(master), datagrid2(sub)数据源的语句
this.dataGrid1.SetDataBinding(df31,"bom_pcs");
this.dataGrid2.SetDataBinding(df31,"bom_pcs.vdfsg");
}