關(guān)鍵代碼 父表 SqlDataAdapter sda = new SqlDataAdapter(); SqlCommand cmd = new SqlCommand(strSQL, myConn); sda.SelectCommand = cmd; sda.Fill(ds, "Parents"); 子表 SqlDataAdapter sda2 = new SqlDataAdapter(); SqlCommand cmd2 = new SqlCommand(strSQL2, myConn); sda2.SelectCommand = cmd2; sda2.Fill(ds, "Sons"); 建立關(guān)系 System.Data.DataRelation dataRelation; System.Data.DataColumn dataColumn1; System.Data.DataColumn dataColumn2;
dataColumn1 = ds.Tables["Parents"].Columns["YBID"];//設(shè)定表關(guān)系 dataColumn2 = ds.Tables["Sons"].Columns["標(biāo)準(zhǔn)樣板ID"]; dataRelation = new System.Data.DataRelation("ParentsSons", dataColumn1, dataColumn2);
|