c#, DataSets and DataTables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wendlinSteele
    New Member
    • Feb 2008
    • 1

    c#, DataSets and DataTables

    I'm a noob at c# so bear with me.

    Basically I have a dataSet and I want to pass a dataTable within the dataSet to another function but Im not sure if im doing it correct.

    functionOne()
    {
    foreach (DataTable DocTable in myDataSet.Table s["DocumentTa ble"])
    {
    functionTwo(Doc Table);
    }
    }

    functionTwo(Dat aTable DocTable)
    {
    //and In here I could parse the information within that particular dataTable
    }

    Is this logic correct?
  • dipalichavan82
    New Member
    • Feb 2008
    • 41

    #2
    i tried ur prob this way:





    protected void Page_Load(objec t sender, EventArgs e)
    {
    SqlDataAdapter adap1 = new SqlDataAdapter( "select OrderID from Orders", con);
    SqlDataAdapter adap2 = new SqlDataAdapter( "select CustomerID from Orders", con);

    adap1.Fill(ds, "tab1");
    adap2.Fill(ds, "tab2");
    GridView1.DataS ource = ds;
    GridView2.DataS ource = ds;
    // GridView1.DataB ind();
    // GridView2.DataB ind();
    fun1();




    }
    public void fun1()
    {
    foreach (DataTable dt in ds)
    {
    fun2(dt);
    }
    }

    public void fun2(DataTable dt1)
    {
    if (dt1 == "tab1")
    GridView1.DataB ind();
    else if (dt1 == "tab2")
    GridView2.DataB ind();

    }

    i got a error:
    foreach statement cannot operate on variables of type 'System.Data.Da taSet' because 'System.Data.Da taSet' does not contain a public definition for 'GetEnumerator'


    search more on this error, u ll find solution

    Comment

    • dipalichavan82
      New Member
      • Feb 2008
      • 41

      #3
      we can access datatable in dataset by index.
      like ds.tables[i]; u can try this way. i havent tried this but u can check it out.
      submit solution if u find any

      Comment

      Working...