Manipulating Datasets

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anil Gupte

    Manipulating Datasets

    How can I manipulate Datasets, such as getting a specific row based on a key
    column value. Of course, I could loop through all the rows in the entire
    dataset each time I needed something, but is there an easier way? I want to
    be able to execute the equivalent of SQL statements including insert, delete
    etc.

    Any ideas? Thanx,
    --
    Anil Gupte
    Innovate with UsLeading the Way in Advanced Technology Solutions Discover state-of-the-art services in logistics, databases, and AI designed for evolving




  • sloan

    #2
    Re: Manipulating Datasets


    You have to

    1. Perform a .Select
    2. Change the data
    3. (Sometimes) commit the changes



    Let's say you have a strong dataset called EmployeeDS with an
    Employee(table) . EmpID(int),Last Name(string),Fi rstName(string)


    EmployeeDS ds = //populate the ds somehow with employees

    DataRow[] rows = ds.Select("EmpI D=123");
    //vb dim rows as DataRows() = ds.Select("EmpI D=123");
    //or
    //DataRow[]rows = ds.Select("Last Name='Smith'");
    //or vb
    //dim rows as DataRows() = ds.Select("Last Name='Smith'");

    now you have an array of rows

    you loop over them, but you'll have to cast them

    dim i as integer
    for i = 0 to rows.Length - 1 //or .Count?
    EmployeeDS.Empl oyeeRow currentRow = ctype(rows(i),
    EmployeeDS.Empl oyeeRow
    currentRow.Last Name = "Jones" //change the data

    next i

    Console.Writeli ne (ds.GetXml())



    Something like that.





    "Anil Gupte" <anil-list@icinema.co mwrote in message
    news:uz%232TvTf IHA.1824@TK2MSF TNGP02.phx.gbl. ..
    How can I manipulate Datasets, such as getting a specific row based on a
    key column value. Of course, I could loop through all the rows in the
    entire dataset each time I needed something, but is there an easier way?
    I want to be able to execute the equivalent of SQL statements including
    insert, delete etc.
    >
    Any ideas? Thanx,
    --
    Anil Gupte
    Innovate with UsLeading the Way in Advanced Technology Solutions Discover state-of-the-art services in logistics, databases, and AI designed for evolving


    >
    >

    Comment

    • Steve Gerrard

      #3
      Re: Manipulating Datasets

      Anil Gupte wrote:
      I thought DataViews were read-only? I am using VB.Net 2003
      >
      How so? A DataView is just a another look at rows in a DataTable.

      Some ways to modify data in through a DataView:

      Dim DV As DataView = New DataView(MyTabl e)
      DV.Item(3).Item ("CheckFlag" ) = 1

      Dim drv As DataRowView
      drv = DV.Item(3)
      drv("CheckFlag" ) = 1

      For Each drv In DV
      drv("CheckFlag" ) = 1
      Next drv

      Dim nID As Integer = 23
      dv.Sort = "EmpID"
      drv = dv.FindRows(nID ).GetValue(0)
      drv("CheckFlag" ) = 1

      ' etc...


      Comment

      • Cor Ligthert[MVP]

        #4
        Re: Manipulating Datasets

        Steve,
        It's a mini-database. :)
        It is certainly not or should add to your text, "single user", this has
        given very much misunderstandin gs in past.

        One of the disadvantages is than even that you have to read and write
        forever the complete XML file while it is not changeble on disk.

        Cor


        Comment

        • Cor Ligthert[MVP]

          #5
          Re: Manipulating Datasets

          Anil-

          A little addition to your two other answers,



          -Cor

          "Anil Gupte" <anil-list@icinema.co mschreef in bericht
          news:uz%232TvTf IHA.1824@TK2MSF TNGP02.phx.gbl. ..
          How can I manipulate Datasets, such as getting a specific row based on a
          key column value. Of course, I could loop through all the rows in the
          entire dataset each time I needed something, but is there an easier way?
          I want to be able to execute the equivalent of SQL statements including
          insert, delete etc.
          >
          Any ideas? Thanx,
          --
          Anil Gupte
          Innovate with UsLeading the Way in Advanced Technology Solutions Discover state-of-the-art services in logistics, databases, and AI designed for evolving


          >
          >

          Comment

          • Anil Gupte

            #6
            Re: Manipulating Datasets

            From Sams Teach Yourself Visual Basic in 21 Days on page 714:

            "Dataviews are much like read-only datasets. Because they're read-only,
            they work like snapshots of your data, and they provide you with faster
            access to that data than datasets can. The term "data view" means just
            that - a view of your data - and they're usually used as containers for a
            subset of your data."

            --
            Anil Gupte
            Innovate with UsLeading the Way in Advanced Technology Solutions Discover state-of-the-art services in logistics, databases, and AI designed for evolving



            "Steve Gerrard" <mynamehere@com cast.netwrote in message
            news:LqKdnXt8b_ YaV1HanZ2dnUVZ_ hynnZ2d@comcast .com...
            Anil Gupte wrote:
            >I thought DataViews were read-only? I am using VB.Net 2003
            >>
            >
            How so? A DataView is just a another look at rows in a DataTable.
            >
            Some ways to modify data in through a DataView:
            >
            Dim DV As DataView = New DataView(MyTabl e)
            DV.Item(3).Item ("CheckFlag" ) = 1
            >
            Dim drv As DataRowView
            drv = DV.Item(3)
            drv("CheckFlag" ) = 1
            >
            For Each drv In DV
            drv("CheckFlag" ) = 1
            Next drv
            >
            Dim nID As Integer = 23
            dv.Sort = "EmpID"
            drv = dv.FindRows(nID ).GetValue(0)
            drv("CheckFlag" ) = 1
            >
            ' etc...
            >
            >

            Comment

            Working...