Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem in DataSet

Problem in DataSet

Scheduled Pinned Locked Moved C#
help
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vinay_K
    wrote on last edited by
    #1

    hi. Please see the following code. HistoryData is also a dataset..

    string strExpression = "Date >= '1/2/2009' And Date <= 2/2/2009"

    Dataset dsData = HistoryData;
    DataSet dsNew = new DataSet();

    DataTable dt = dsData.Tables[0];

    DataRow dr = dt.Select(strExpression);

    in the above code it gives the filtered rows into dr. but i need to apply the select command to dataset and copy the filtered data into new dataset. Please help me..

    K A 2 Replies Last reply
    0
    • V vinay_K

      hi. Please see the following code. HistoryData is also a dataset..

      string strExpression = "Date >= '1/2/2009' And Date <= 2/2/2009"

      Dataset dsData = HistoryData;
      DataSet dsNew = new DataSet();

      DataTable dt = dsData.Tables[0];

      DataRow dr = dt.Select(strExpression);

      in the above code it gives the filtered rows into dr. but i need to apply the select command to dataset and copy the filtered data into new dataset. Please help me..

      K Offline
      K Offline
      Kaushal Arora
      wrote on last edited by
      #2

      Hi, first of all the statement: DataRow dr = dt.Select(strExpression); will return the array of rows not a single row. So it will be DataRow[] dr = dt.Select(strExpression); After this you can traverse in the DataRow using Foreach and then can add the same in the new table having same columns(structure) foreach (DataRow dr in dt.Select(strExpression)) { DataRow drRow = newtable.NewRow(); // newtable having same structure as of the main table dt drRow["Column1"] = dr["Column1"].ToString(); drRow["Column2"] = dr["Column2"].ToString(); drRow["Column3"] = dr["Column3"].ToString(); ... drRow["Columnn"] = dr["Columnn"].ToString(); drRow.Rows.Add(drRow); newtable.AcceptChanges(); } This way you can get a new table having required rows. Regards, Kaushal Arora

      1 Reply Last reply
      0
      • V vinay_K

        hi. Please see the following code. HistoryData is also a dataset..

        string strExpression = "Date >= '1/2/2009' And Date <= 2/2/2009"

        Dataset dsData = HistoryData;
        DataSet dsNew = new DataSet();

        DataTable dt = dsData.Tables[0];

        DataRow dr = dt.Select(strExpression);

        in the above code it gives the filtered rows into dr. but i need to apply the select command to dataset and copy the filtered data into new dataset. Please help me..

        A Offline
        A Offline
        Abdul Rahman Hamidy
        wrote on last edited by
        #3

        I think better to use DataView to create new table instead looping through all filtered rows and add them to datatable i am suggesting following [code] DataView dva1=new DataView(dataTable or dataSet); DataTable dt=dva1.toTable(filterString); [/code]

        Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

        K 1 Reply Last reply
        0
        • A Abdul Rahman Hamidy

          I think better to use DataView to create new table instead looping through all filtered rows and add them to datatable i am suggesting following [code] DataView dva1=new DataView(dataTable or dataSet); DataTable dt=dva1.toTable(filterString); [/code]

          Abdul Rahaman Hamidy Database Developer Kabul, Afghanistan

          K Offline
          K Offline
          Kaushal Arora
          wrote on last edited by
          #4

          I didnt find any option in which i can give the filterstring in the arguments. Kindly elaborate the answer in detail. If you have any sample code then share.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups