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. Datasets & RowStates

Datasets & RowStates

Scheduled Pinned Locked Moved C#
questionsalestutorial
3 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.
  • F Offline
    F Offline
    farhan1976
    wrote on last edited by
    #1

    Hi guyz, I got a quick question regarding DataSets and RowState. In the following code sample I populate a DataSet, then modifies two rows, and call the DataRow.AcceptChanges(). But when i retrieve the Rowstate of those edit Rows it says "UNCHANGED". shouldn't be "MODIFIED". If not, then WHY????? here is the code : namespace DSEditEx { /// /// Summary description for dsClass. /// public class dsClass { //private variable which represents a DataSet private DataSet ds; public dsClass() { //instantiate the ds = new DataSet(); try { //Initialize ds ds = new DataSet(); //define the first data table DataTable tblCustomer = new DataTable(); //define and add columns to ds DataColumn custID = new DataColumn(); custID.ColumnName = "CustomerID"; custID.ColumnName = "Customer ID"; custID.AllowDBNull = false; custID.DataType = System.Type.GetType("System.Int16"); tblCustomer.Columns.Add(custID); DataColumn fn = new DataColumn(); fn.ColumnName = "FirstName"; fn.Caption = "First Name"; fn.AllowDBNull = false; fn.DataType = System.Type.GetType("System.String"); tblCustomer.Columns.Add(fn); DataColumn ln = new DataColumn(); ln.ColumnName = "LastName"; ln.Caption = "Last Name"; ln.AllowDBNull = false; ln.DataType = System.Type.GetType("System.String"); tblCustomer.Columns.Add(ln); //adding the table -> ds ds.Tables.Add(tblCustomer); //load some data into datatable 1 -> tblCustomers DataRow r; for(int i=0; i < 10; i++) { r = ds.Tables[0].NewRow(); r[0] = i; r[1] = "Farhan_" + i; r[2] = "Munir_" + i; tblCustomer.Rows.Add(r); } } catch(Exception ex) { Console.WriteLine(ex.ToString()); } } //public method which illustrates how to edit values //in the datarow. How to check the state of the DataRow public void DemoDSEdit() { try { //we are going to modify Row[0] DataRow editRow = ds.Tables[0].Rows[0]; //we are going to modify the first and last name editRow[1] = "John"; editRow[2] = "Doe"; //Now check the state of all Rows //Note we haven't commit any changes yet Console.WriteLine("Checking the Row State"); for(int i=0; i < ds.Tables[0].Rows.Count; i++) Console.WriteLine("State of Row[" + i

    D L 2 Replies Last reply
    0
    • F farhan1976

      Hi guyz, I got a quick question regarding DataSets and RowState. In the following code sample I populate a DataSet, then modifies two rows, and call the DataRow.AcceptChanges(). But when i retrieve the Rowstate of those edit Rows it says "UNCHANGED". shouldn't be "MODIFIED". If not, then WHY????? here is the code : namespace DSEditEx { /// /// Summary description for dsClass. /// public class dsClass { //private variable which represents a DataSet private DataSet ds; public dsClass() { //instantiate the ds = new DataSet(); try { //Initialize ds ds = new DataSet(); //define the first data table DataTable tblCustomer = new DataTable(); //define and add columns to ds DataColumn custID = new DataColumn(); custID.ColumnName = "CustomerID"; custID.ColumnName = "Customer ID"; custID.AllowDBNull = false; custID.DataType = System.Type.GetType("System.Int16"); tblCustomer.Columns.Add(custID); DataColumn fn = new DataColumn(); fn.ColumnName = "FirstName"; fn.Caption = "First Name"; fn.AllowDBNull = false; fn.DataType = System.Type.GetType("System.String"); tblCustomer.Columns.Add(fn); DataColumn ln = new DataColumn(); ln.ColumnName = "LastName"; ln.Caption = "Last Name"; ln.AllowDBNull = false; ln.DataType = System.Type.GetType("System.String"); tblCustomer.Columns.Add(ln); //adding the table -> ds ds.Tables.Add(tblCustomer); //load some data into datatable 1 -> tblCustomers DataRow r; for(int i=0; i < 10; i++) { r = ds.Tables[0].NewRow(); r[0] = i; r[1] = "Farhan_" + i; r[2] = "Munir_" + i; tblCustomer.Rows.Add(r); } } catch(Exception ex) { Console.WriteLine(ex.ToString()); } } //public method which illustrates how to edit values //in the datarow. How to check the state of the DataRow public void DemoDSEdit() { try { //we are going to modify Row[0] DataRow editRow = ds.Tables[0].Rows[0]; //we are going to modify the first and last name editRow[1] = "John"; editRow[2] = "Doe"; //Now check the state of all Rows //Note we haven't commit any changes yet Console.WriteLine("Checking the Row State"); for(int i=0; i < ds.Tables[0].Rows.Count; i++) Console.WriteLine("State of Row[" + i

      D Offline
      D Offline
      david cohoon
      wrote on last edited by
      #2

      If you want the rows to remain as MODIFIED, do not call AcceptChanges(). By calling AcceptChanges() you are commanding the data row(s) to end the current edit.

      1 Reply Last reply
      0
      • F farhan1976

        Hi guyz, I got a quick question regarding DataSets and RowState. In the following code sample I populate a DataSet, then modifies two rows, and call the DataRow.AcceptChanges(). But when i retrieve the Rowstate of those edit Rows it says "UNCHANGED". shouldn't be "MODIFIED". If not, then WHY????? here is the code : namespace DSEditEx { /// /// Summary description for dsClass. /// public class dsClass { //private variable which represents a DataSet private DataSet ds; public dsClass() { //instantiate the ds = new DataSet(); try { //Initialize ds ds = new DataSet(); //define the first data table DataTable tblCustomer = new DataTable(); //define and add columns to ds DataColumn custID = new DataColumn(); custID.ColumnName = "CustomerID"; custID.ColumnName = "Customer ID"; custID.AllowDBNull = false; custID.DataType = System.Type.GetType("System.Int16"); tblCustomer.Columns.Add(custID); DataColumn fn = new DataColumn(); fn.ColumnName = "FirstName"; fn.Caption = "First Name"; fn.AllowDBNull = false; fn.DataType = System.Type.GetType("System.String"); tblCustomer.Columns.Add(fn); DataColumn ln = new DataColumn(); ln.ColumnName = "LastName"; ln.Caption = "Last Name"; ln.AllowDBNull = false; ln.DataType = System.Type.GetType("System.String"); tblCustomer.Columns.Add(ln); //adding the table -> ds ds.Tables.Add(tblCustomer); //load some data into datatable 1 -> tblCustomers DataRow r; for(int i=0; i < 10; i++) { r = ds.Tables[0].NewRow(); r[0] = i; r[1] = "Farhan_" + i; r[2] = "Munir_" + i; tblCustomer.Rows.Add(r); } } catch(Exception ex) { Console.WriteLine(ex.ToString()); } } //public method which illustrates how to edit values //in the datarow. How to check the state of the DataRow public void DemoDSEdit() { try { //we are going to modify Row[0] DataRow editRow = ds.Tables[0].Rows[0]; //we are going to modify the first and last name editRow[1] = "John"; editRow[2] = "Doe"; //Now check the state of all Rows //Note we haven't commit any changes yet Console.WriteLine("Checking the Row State"); for(int i=0; i < ds.Tables[0].Rows.Count; i++) Console.WriteLine("State of Row[" + i

        L Offline
        L Offline
        Luis Alonso Ramos
        wrote on last edited by
        #3

        The idea is that you perform the editions on the rows (add, delete, modify) and then, somewhere else, you check which rows have been modified and save only those to the database. You then call AcceptChanges. Then, after the next set of changes, only the newly-changed rows will require saving to the real database. If you use a data adapter, it automatically calls AcceptChanges in Update after updating the database. -- LuisR


        Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!

        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