Click here to Skip to main content
15,910,083 members
Home / Discussions / C#
   

C#

 
GeneralRe: graphics.Clear(color) - Incorrect color! Pin
Dan Neely27-Jun-05 10:47
Dan Neely27-Jun-05 10:47 
GeneralRe: graphics.Clear(color) - Incorrect color! Pin
Roger Alsing28-Jun-05 2:30
Roger Alsing28-Jun-05 2:30 
GeneralRe: graphics.Clear(color) - Incorrect color! Pin
Anthony Baraff28-Jun-05 2:32
Anthony Baraff28-Jun-05 2:32 
GeneralRichTextBox, manipulating RTF directly Pin
Daniel Monzert27-Jun-05 7:31
Daniel Monzert27-Jun-05 7:31 
GeneralUser Control MouseEnter MouseLeave Problems Pin
notacake27-Jun-05 6:36
notacake27-Jun-05 6:36 
GeneralRe: User Control MouseEnter MouseLeave Problems Pin
david cohoon27-Jun-05 7:38
david cohoon27-Jun-05 7:38 
GeneralRe: User Control MouseEnter MouseLeave Problems Pin
notacake27-Jun-05 8:26
notacake27-Jun-05 8:26 
GeneralDatasets & RowStates Pin
farhan197627-Jun-05 5:26
farhan197627-Jun-05 5:26 
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 <ds>
private DataSet ds;

public dsClass()
{
//instantiate the <ds>
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 + "] : " + ds.Tables[0].Rows[i].RowState.ToString());

//Now Commit changes and again

check the State of Row
Console.WriteLine("\nCommitting

Changes and Checking the RowState");
editRow.AcceptChanges();
for(int i=0; i <

ds.Tables[0].Rows.Count; i++)
Console.WriteLine("State of

Row[" + i + "] : " + ds.Tables[0].Rows[i].RowState.ToString());

//Modify the Row[0] again
editRow = null;
editRow = ds.Tables[0].Rows[1];
editRow[1] = "Jane";
editRow[2] = "Munir";
Console.WriteLine("\nCommitting

Changes and Checking the RowState");
editRow.AcceptChanges();
for(int i=0; i <

ds.Tables[0].Rows.Count; i++)
Console.WriteLine("State of

Row[" + i + "] : " + ds.Tables[0].Rows[i].RowState.ToString());
}
catch(Exception ex) {

Console.WriteLine(ex.ToString()); }
}
}
}

----------------------------------------
OUTPUT is :
----------------------------------------
Checking the Row State
State of Row[0] : Added
State of Row[1] : Added
State of Row[2] : Added
State of Row[3] : Added
State of Row[4] : Added
State of Row[5] : Added
State of Row[6] : Added
State of Row[7] : Added
State of Row[8] : Added
State of Row[9] : Added

Committing Changes and Checking the RowState
State of Row[0] : Unchanged
State of Row[1] : Added
State of Row[2] : Added
State of Row[3] : Added
State of Row[4] : Added
State of Row[5] : Added
State of Row[6] : Added
State of Row[7] : Added
State of Row[8] : Added
State of Row[9] : Added

Committing Changes and Checking the RowState
State of Row[0] : Unchanged
State of Row[1] : Unchanged
State of Row[2] : Added
State of Row[3] : Added
State of Row[4] : Added
State of Row[5] : Added
State of Row[6] : Added
State of Row[7] : Added
State of Row[8] : Added
State of Row[9] : Added
GeneralRe: Datasets &amp; RowStates Pin
david cohoon27-Jun-05 7:41
david cohoon27-Jun-05 7:41 
GeneralRe: Datasets &amp; RowStates Pin
Luis Alonso Ramos27-Jun-05 9:30
Luis Alonso Ramos27-Jun-05 9:30 
Generalshared folders Pin
amarsumanth27-Jun-05 4:54
amarsumanth27-Jun-05 4:54 
GeneralRe: shared folders Pin
Judah Gabriel Himango27-Jun-05 8:57
sponsorJudah Gabriel Himango27-Jun-05 8:57 
GeneralAre you good with Maths API Pin
hasanali0027-Jun-05 4:05
hasanali0027-Jun-05 4:05 
GeneralRe: Are you good with Maths API Pin
DavidNohejl27-Jun-05 4:13
DavidNohejl27-Jun-05 4:13 
GeneralRe: Are you good with Maths API Pin
mav.northwind27-Jun-05 4:19
mav.northwind27-Jun-05 4:19 
GeneralRe: Are you good with Maths API Pin
Roger Wright27-Jun-05 4:28
professionalRoger Wright27-Jun-05 4:28 
GeneralRe: Are you good with Maths API Pin
Stefan Troschuetz27-Jun-05 4:33
Stefan Troschuetz27-Jun-05 4:33 
GeneralRe: Are you good with Maths API Pin
Daniel Monzert27-Jun-05 4:44
Daniel Monzert27-Jun-05 4:44 
GeneralRe: Are you good with Maths API Pin
Daniel Monzert27-Jun-05 5:09
Daniel Monzert27-Jun-05 5:09 
GeneralRe: Are you good with Maths API Pin
mav.northwind27-Jun-05 5:44
mav.northwind27-Jun-05 5:44 
GeneralRe: Are you good with Maths API Pin
StylezHouse27-Jun-05 9:49
StylezHouse27-Jun-05 9:49 
GeneralRe: Are you good with Maths API Pin
Daniel Monzert27-Jun-05 10:15
Daniel Monzert27-Jun-05 10:15 
GeneralRe: Are you good with Maths API Pin
Niklas Ulvinge27-Jun-05 9:49
Niklas Ulvinge27-Jun-05 9:49 
GeneralRe: Are you good with Maths API Pin
hasanali0027-Jun-05 23:01
hasanali0027-Jun-05 23:01 
GeneralOdbc Dataadapter error Pin
V.27-Jun-05 3:12
professionalV.27-Jun-05 3:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.