J
Jeff
I'm importing data from an Excel file into an untyped DataSet.
I need to find any rows in the DataSet that have a NULL value in a specific
column (say, the "FirstName" column). These would result from any any
"blank" cells coming in from the Excel file.
I don't want to loop through the entire DataSet using the row.IsNull()
function, as I would prefer some more set based approach, like .Select.
So, finding no way to .Select() NULLs specifically; something like this:
DataRow[] nullRows;
nullRows = DT_ExcelData.Select("FirstName = System.DBNull.Value"); //
obviously won't work
I went with this, which *seems* to do the trick:
int nullRowCount = 0;
DataRow[] notNullRows;
notNullRows= DT_ExcelData.Select("FirstName LIKE '%'"); // This gets all of
the NON NULL values:
nullRowCount = (DT_ExcelData.Rows.Count - notNullRows.Length); // The
difference between ALL the rows and the NON Null ones tells me if I have any
NULLs and, if so, how many.
if (nullRowCount > 0) {
// do one thing
}
else {
// do another
}
While I searched high and low for something more reasonable, I'm hoping I
just missed it, as my "work-around" smacks of a Rube Goldberg device.
Any suggestions? Thoughts? Perspective?
Thanks!
I need to find any rows in the DataSet that have a NULL value in a specific
column (say, the "FirstName" column). These would result from any any
"blank" cells coming in from the Excel file.
I don't want to loop through the entire DataSet using the row.IsNull()
function, as I would prefer some more set based approach, like .Select.
So, finding no way to .Select() NULLs specifically; something like this:
DataRow[] nullRows;
nullRows = DT_ExcelData.Select("FirstName = System.DBNull.Value"); //
obviously won't work
I went with this, which *seems* to do the trick:
int nullRowCount = 0;
DataRow[] notNullRows;
notNullRows= DT_ExcelData.Select("FirstName LIKE '%'"); // This gets all of
the NON NULL values:
nullRowCount = (DT_ExcelData.Rows.Count - notNullRows.Length); // The
difference between ALL the rows and the NON Null ones tells me if I have any
NULLs and, if so, how many.
if (nullRowCount > 0) {
// do one thing
}
else {
// do another
}
While I searched high and low for something more reasonable, I'm hoping I
just missed it, as my "work-around" smacks of a Rube Goldberg device.
Any suggestions? Thoughts? Perspective?
Thanks!