资源描述:
《计算机科学与技术:VB.NET应用教程 978-7-302-09622-1 Advanced VB.NET Chapter 13》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Chapter13MultitableDataSetsObjectivesMultitableDatasetsBuildingaDatasetwithoutaDataAdapterAdditionalDataRowMethodsandPropertiesLab13.1:SingleTableDatasetLab13.2:ExamineDataRelationsandConstraintsLab13.3:CreateaDatasetwithaDataTableandDataColumnsGeneralPracticeLab:ALibraryApp
2、licationSuggestedHomeAssignments2Copyright2004PearsonEducation,Inc.MultitableDatasetsWhyMultitableDatasets?Dataarehandleddisconnected,Sodatasetsmustmakeupformissingdatabasefunctionality,Constraintsmustbecheckedbeforetheyareupdatedtothedatasource.Recall,theDataFormWizardalsoc
3、opiedtheConstraintsHandlethedatasetasanobject,Versioning,Inheritance,PersistentObjects.3Copyright2004PearsonEducation,Inc.BuildingaMultitableDatasetMergingtwoDatasetsfilledbyaDataAdapter.DimmyDataset1,myDataset2AsDataSetDimintSizeAsInteger'BuiltdatasetwithbothtablesmyDataset
4、1=NewDataSet()myDataset2=NewDataSet()intSize=SqlDataAdapter1.Fill(myDataset1)intSize=SqlDataAdapter2.Fill(myDataset2)myDataset1.Merge(myDataset2)4Copyright2004PearsonEducation,Inc.And,ThereisaCollectionofTablesDimmyTableAsDataTableDimmyRowsAsDataRowDimmyColAsDataColumnDimI,i
5、ntTableNumberAsIntegerDimstrRow,strColumnsAsStringintTableNumber=0ForEachmyTableInmyDataset1.Tables'listoftablesfromthecollectionlstPets.Items.Add("Table"&_myDataset1.Tables(intTableNumber).TableName)Next5Copyright2004PearsonEducation,Inc.AddingConstraintsThetwotablesarestil
6、lunrelated.Addingaconstraintwilltiethemtogether.DimmyRelationAsDataRelationDimmyParentCol,myChildColAsDataColumnmyParentCol=NewDataColumn()myChildCol=NewDataColumn()myParentCol=_myDataset1.Tables("Friends").Columns("FriendID")myChildCol=_myDataset1.Tables("Pets").Columns("Fr
7、iendID")myRelation=NewDataRelation_("FriendsandtheirPets",myParentCol,myChildCol,True)myDataset1.Relations.Add(myRelation)6Copyright2004PearsonEducation,Inc.AccessingtheRelationsDimmyConstraintAsConstraintForEachmyConstraintIn_myDataset1.Tables(0).ConstraintslstPets.Items.Ad
8、d("Constraintnameis"&_myConstraint.ConstraintName&_"Tableis"&myConstraint.T