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

Reset() public method

Resets the dataSet back to it's original state. Subclasses should override to restore back to it's original state.
public Reset ( ) : void
return void
        public virtual void Reset()
        {
            long logScopeId = DataCommonEventSource.Log.EnterScope("<ds.DataSet.Reset|API> {0}", ObjectID);
            try
            {
                for (int i = 0; i < Tables.Count; i++)
                {
                    ConstraintCollection cons = Tables[i].Constraints;
                    for (int j = 0; j < cons.Count;)
                    {
                        if (cons[j] is ForeignKeyConstraint)
                        {
                            cons.Remove(cons[j]);
                        }
                        else
                        {
                            j++;
                        }
                    }
                }

                Clear();
                Relations.Clear();
                Tables.Clear();
            }
            finally
            {
                DataCommonEventSource.Log.ExitScope(logScopeId);
            }
        }

Usage Example

        public DataTable ExecuteSelectQuery(NpgsqlCommand command, NpgsqlConnection conn)
        {
            try
            {
                if (conn == null)
                {
                    return null;
                }

                DataTable dataTable = new DataTable();
                DataSet dataSet = new DataSet();
                NpgsqlDataAdapter dataAdapter = new NpgsqlDataAdapter(command);
                dataSet.Reset();
                dataAdapter.Fill(dataSet);
                dataTable = dataSet.Tables[0];
                conn.Close();

                return dataTable.Rows.Count <= 0 ? null : dataTable;
            }
            catch (NpgsqlException ex)
            {
                Console.WriteLine(ex.Message);
                return null;
            }
        }
All Usage Examples Of System.Data.DataSet::Reset