Is it possible to JOIN a Dataset table? ASP.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rkhiev
    New Member
    • Oct 2008
    • 3

    Is it possible to JOIN a Dataset table? ASP.NET

    For example in my code i am calling three slqadapter and stored it into three dataset.

    Dataset 1

    Description Shift1
    PRINT 2
    MOUSE 3
    MONITOR 1

    dataset 2

    Description Shift2
    PRINT 1
    MOUSE 1
    MONITOR 1

    dataset 3

    Description Shift3
    PRINT 2
    MOUSE 3
    MONITOR 4

    I would like to view all three dataset into one datset and display it on a gridview.



    Description Shift1 Shift2 Shift3
    PRINT 2 1 2
    MOUSE 3 1 3
    MONITOR 1 1 4

    I need all of your help. please provide me with some example codes.

    Thank you in advance.
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    rkhiev,

    I assume you are talking about ASP.NET since ASP has neither gridViews nor DataSet objects. The ASP forum is for "classic" ASP only. I will go ahead and move your question to the correct forum, but please post all .NET questions in the future into the .NET forum.

    What you are asking to do is fairly easy and straight-forward programatically , but I'm not sure it is really the best solution. Anyway, it looks something like this:
    Code:
    myDataSet.Tables["myTable"].Columns.Add("Shift2", typeof(int))
    myDataSet.Tables["myTable"].Columns.Add("Shift3", typeof(int))
    for (int i = 0; i<myDataSet.Tables["myTable"].Rows.Count; i++)
       {
       myDataSet.Tables["myTable"].Rows[i]["Shift2"] = mySecondDS.Tables["myTable"].Rows[i]["Shift2"]
       myDataSet.Tables["myTable"].Rows[i]["Shift3"] = myThirdDS.Tables["myTable"].Rows[i]["Shift3"]
       }
    but it seems to me it would make more sense to list these fields:
    Shift print mouse monitor
    and these rows:
    1 1 1 1
    2 1 2 3
    3 2 1 1

    How is the data coming in?

    Jared

    Comment

    • rkhiev
      New Member
      • Oct 2008
      • 3

      #3
      thanks for the reply.. but the table you provided me is that a single sqlAdapter table or a dataset. sorry maybe i am not clear about my question.

      i want to iterate through my dataset and delete all duplicate column and leave the value column and add into a newer column. for example
      here is my result of my code:

      this is my Dataset and it will look this in my gridview

      Description ResultValue
      Print 1
      Monitor 1
      Mouse 1
      Keyboard 1
      LCD 1
      Print 2
      Monitor 2
      Mouse 2
      Keyboard 2
      LCD 2
      Print 3
      Monitor 3
      Mouse 3
      Keyboard 3
      LCD 3


      This is how i wanted the result to look like


      Description ResultValue ResultValue ResultValue
      Print 1 2 3
      Monitor 1 2 3
      Mouse 1 2 3
      Keyboard 1 2 3
      LCD 1 2 3

      Thank you inadvance

      Comment

      • rkhiev
        New Member
        • Oct 2008
        • 3

        #4
        I tried using your code

        ds.Tables[0].Columns.Add("S hift2", typeof(int));
        ds.Tables[0].Columns.Add("S hift3", typeof(int)) ;


        for (int i = 0; i<ds.Tables[0].Rows.Count; i++)
        {

        ds.Tables[0].Rows[i]["Shift2"] = mySecondDS.Tabl es[0].Rows[i]["Shift2"];
        ds.Tables[0].Rows[i]["Shift3"] = myThirdDS.Table s[0].Rows[i]["Shift3"];
        }

        but it gave me an error on line bolded

        Column 'Shift2' does not belong to table Table.

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Check out this article on How to implement DataSet JOIN helper class in Visual C# .NET.

          -Frinny

          Comment

          Working...