System.Data.DataSet.HasChanges C# (CSharp) Method

HasChanges() public method

Gets a value indicating whether the has changes, including new, deleted, or modified rows, filtered by .
public HasChanges ( DataRowState rowStates ) : bool
rowStates DataRowState
return bool
        public bool HasChanges(DataRowState rowStates)
        {
            long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataSet.HasChanges|API> {0}, rowStates={1}", ObjectID, (int)rowStates);
            try
            {
                const DataRowState allRowStates = DataRowState.Detached | DataRowState.Unchanged | DataRowState.Added | DataRowState.Deleted | DataRowState.Modified;

                if ((rowStates & (~allRowStates)) != 0)
                {
                    throw ExceptionBuilder.ArgumentOutOfRange("rowState");
                }

                for (int i = 0; i < Tables.Count; i++)
                {
                    DataTable table = Tables[i];

                    for (int j = 0; j < table.Rows.Count; j++)
                    {
                        DataRow row = table.Rows[j];
                        if ((row.RowState & rowStates) != 0)
                        {
                            return true;
                        }
                    }
                }
                return false;
            }
            finally
            {
                DataCommonEventSource.Log.ExitScope(logScopeId);
            }
        }

Same methods

DataSet::HasChanges ( ) : bool

Usage Example

Beispiel #1
0
	//Activate This Construntor to log All To Standard output
	//public TestClass():base(true){}

	//Activate this constructor to log Failures to a log file
	//public TestClass(System.IO.TextWriter tw):base(tw, false){}


	//Activate this constructor to log All to a log file
	//public TestClass(System.IO.TextWriter tw):base(tw, true){}

	//BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES

	public void run()
	{
		Exception exp = null;
	
		DataSet ds = new DataSet();
		ds.Tables.Add(GHTUtils.DataProvider.CreateParentDataTable());

		try
		{
			BeginCase("HasChanges 1");
			Compare(ds.HasChanges(),false );
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}
		
		DataRow dr = ds.Tables[0].NewRow();
		dr[0] = 9;
		ds.Tables[0].Rows.Add(dr);
		
		try
		{
			BeginCase("HasChanges 2");
			Compare(ds.HasChanges(),true );
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}
	}
All Usage Examples Of System.Data.DataSet::HasChanges