Converting dataset to dataview and sorting?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brett Romero

    #1

    Converting dataset to dataview and sorting?

    I have a dataset with one table, which has four columns. All are of
    type INT. I need to convert this dataset into a dataview so I can sort
    on the last three columns. I may sort one of the three or all three at
    once. This dataview will display its results in a winform datagrid.

    Right now, I create the dataset from a datareader:

    while(dr.Read() )
    {
    drow = _filteredCriter iaDataSet.Table s[0].NewRow();
    drow[0] = dr.GetValue(0);
    drow[1] = dr.GetValue(1);
    drow[2] = dr.GetValue(2);
    drow[3] = dr.GetValue(3);
    _filteredCriter iaDataSet.Table s[0].Rows.Add(drow) ;
    }

    How do I convert the dataset to a dataview then take the three criteria
    and apply them to the new created dataview?

    Thanks,
    Brett

  • KJ

    #2
    Re: Converting dataset to dataview and sorting?

    Where "dt" represents your table and "foo" the column name to sort on:

    DataView dv = new DataView(dt);
    dv.Sort = "foo";

    Comment

    • Brett Romero

      #3
      Re: Converting dataset to dataview and sorting?

      I did that but need to sort this way:

      "col1 = " + col1criteria + " and col2 = " + col2criteria + " and col3 =
      " + col3criteria

      I apply that to the sortfilter but always get the same results in the
      grid, which don't match the above sorting. I can look at "dv" in the
      debugger and see its "Items". The row values are matching the criteria
      I'm sending in. What could be causing it not to match the query?

      Thanks,
      Brett

      Comment

      • KJ

        #4
        Re: Converting dataset to dataview and sorting?

        OK, maybe you are thinking of the .Select method of DataTable?:

        (from MSDN)

        public DataRow[] Select(
        string filterExpressio n,
        string sort,
        DataViewRowStat e recordStates
        );

        Comment

        • Brett Romero

          #5
          Re: Converting dataset to dataview and sorting?

          I did try .Select but get the same thing - nothing. For some reason,
          none of the sorting or querying has any affect.

          Brett

          Comment

          • Nicholas Paldino [.NET/C# MVP]

            #6
            Re: Converting dataset to dataview and sorting?

            Brett,

            Sorting is a way of ordering results.

            What you are doing is trying to filter the results. You want to set the
            RowFilter property to this string, and then it should filter your results
            out appropriately.

            Hope this helps.


            --
            - Nicholas Paldino [.NET/C# MVP]
            - mvp@spam.guard. caspershouse.co m

            "Brett Romero" <account@cygen. com> wrote in message
            news:1136003815 .348907.83920@g 47g2000cwa.goog legroups.com...[color=blue]
            >I did that but need to sort this way:
            >
            > "col1 = " + col1criteria + " and col2 = " + col2criteria + " and col3 =
            > " + col3criteria
            >
            > I apply that to the sortfilter but always get the same results in the
            > grid, which don't match the above sorting. I can look at "dv" in the
            > debugger and see its "Items". The row values are matching the criteria
            > I'm sending in. What could be causing it not to match the query?
            >
            > Thanks,
            > Brett
            >[/color]


            Comment

            • Brett Romero

              #7
              Re: Converting dataset to dataview and sorting?

              RowFilter is what I'm setting.

              Comment

              • JTurnham

                #8
                Re: Converting dataset to dataview and sorting?

                I have what I believe to be a similar or the same problem.

                I populate a DataSet with the results of an SQL query, and then apply a
                DataView to this DataSet. I then iterate through the DataView Rows to create
                an XML file.

                My problem is, no matter what I do, the way the data is sorted is always the
                same. so if I sort on "x, y, z" I have unsorted data in my XML file when it
                is saved.

                I don't think this has anything to do with RowFilter properties.

                Thanks in advance

                "Nicholas Paldino [.NET/C# MVP]" wrote:
                [color=blue]
                > Brett,
                >
                > Sorting is a way of ordering results.
                >
                > What you are doing is trying to filter the results. You want to set the
                > RowFilter property to this string, and then it should filter your results
                > out appropriately.
                >
                > Hope this helps.
                >
                >
                > --
                > - Nicholas Paldino [.NET/C# MVP]
                > - mvp@spam.guard. caspershouse.co m
                >
                > "Brett Romero" <account@cygen. com> wrote in message
                > news:1136003815 .348907.83920@g 47g2000cwa.goog legroups.com...[color=green]
                > >I did that but need to sort this way:
                > >
                > > "col1 = " + col1criteria + " and col2 = " + col2criteria + " and col3 =
                > > " + col3criteria
                > >
                > > I apply that to the sortfilter but always get the same results in the
                > > grid, which don't match the above sorting. I can look at "dv" in the
                > > debugger and see its "Items". The row values are matching the criteria
                > > I'm sending in. What could be causing it not to match the query?
                > >
                > > Thanks,
                > > Brett
                > >[/color]
                >
                >
                >[/color]

                Comment

                Working...