Still checking for rows (if they exsist) in a DataTable 
Author Message
 Still checking for rows (if they exsist) in a DataTable

Thanks to all that replyed to my post titled "Checking for
Nulls in a DataTable".  All your responses helped but I
realised that my question was not clear.  

I am looking to see if the DataTable has any data in it if
it doesn't then I will update another Datatable with a
value....

if(EPSQ_Data.Tables["WAGEGARN"].Rows[0].IsNull(0))
{                                                      
        EPSQ_Data.Tables["PERSONAL"].Rows[0]["WGNIND"]
= "N";

Quote:
}

else
        EPSQ_Data.Tables["PERSONAL"].Rows[0]["WGNIND"]
= "Y";

But if there is not a row in the DataTable, I get this
execption "System.IndexOutOfRangeException"

Additional information: There is no row at position 0.

Any help is greatly appricated.  

Will



Sun, 31 Oct 2004 21:53:13 GMT  
 Still checking for rows (if they exsist) in a DataTable
Will,

    Don't kick yourself in the a$$ for this, but you can look at the Count
property of the DataRowsCollection exposed by Rows to see if it is zero.
For example:

// See if there are any rows:
if (EPSQ_Data.Tables["WAGEGARN"].Rows.Count)

    Hope this helps.

--
               - Nicholas Paldino [.NET MVP]


Quote:
> Thanks to all that replyed to my post titled "Checking for
> Nulls in a DataTable".  All your responses helped but I
> realised that my question was not clear.

> I am looking to see if the DataTable has any data in it if
> it doesn't then I will update another Datatable with a
> value....

> if(EPSQ_Data.Tables["WAGEGARN"].Rows[0].IsNull(0))
> {
> EPSQ_Data.Tables["PERSONAL"].Rows[0]["WGNIND"]
> = "N";

> }
> else
>         EPSQ_Data.Tables["PERSONAL"].Rows[0]["WGNIND"]
> = "Y";

> But if there is not a row in the DataTable, I get this
> execption "System.IndexOutOfRangeException"

> Additional information: There is no row at position 0.

> Any help is greatly appricated.

> Will



Sun, 31 Oct 2004 21:59:02 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Thread-safe DataTable.Rows.Add

2. DataTable.Rows.InsertAt vs. DataGrid

3. DataSet Issue : How do I add a Row to a DataTable with Identity Column

4. DataGrid/DataTable - event before row added?

5. Data Binding to a DataTable with Multiple Rows

6. Adding row to dataTable

7. Cant remove row from datatable :(((

8. Add Row dynamically to the beginning of datatable in a datagrid

9. Checking for nulls in a Datatable

10. How to judge a thread is still exsists?

11. How to avoid user from entering a new row into the datagrid[which already contains rows]

12. single row updates effect multiple rows....

 

 
Powered by phpBB® Forum Software