dataset problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hasan Afridi
    New Member
    • Aug 2007
    • 1

    #1

    dataset problem

    hi any body tell me that if i have multiple tables in dataset and i want to bind only one to datagrid ,how can i do that?
  • dip_developer
    Recognized Expert Contributor
    • Aug 2006
    • 648

    #2
    Originally posted by Hasan Afridi
    hi any body tell me that if i have multiple tables in dataset and i want to bind only one to datagrid ,how can i do that?
    you just create a dataadapter.... ...fill the dataset table you want like following.....

    [CODE=vbnet]
    myDataAdapter.F ill(myDataset," myTableNameInDa taset")
    [/CODE]

    now bind your grid as usual....

    [CODE=vbnet]
    myGrid.Datasour ce=myDataset.Ta bles("myTableNa meInDataset")[/CODE]

    next time you can fill another table with that same Adapter....

    Comment

    • ammoos
      New Member
      • Apr 2007
      • 100

      #3
      you can use table index for select a particular table from the dataset
      eg:
      SqlDataAdapter da=new SqlDataAdapter( "SELECT ClientName,IDCl ient FROM tbl_ClientDetai ls WHERE IDClient=140;SE LECT IDClient,SiteNa me FROM tbl_SiteDetails WHERE IDClient=140",c on );
      DataSet ds=new DataSet();
      da.Fill(ds);

      if you want to select the first table, then you can use

      DataGrid1.DataS ource=ds.Table[0];
      DataGrid1.DataB ind();

      else
      if you want to select the second table then use
      DataGrid1.DataS ource=ds.Table[1];
      DataGrid1.DataB ind();

      Comment

      Working...