Reputation: 41
I am pulling data from a SQL database, I am filling in missing data that is blank or missing with the following statement.
string.Join(
",",
from
r in siteData.Rows.OfType<DataRow>()
select
r[28] == DBNull.Value ? "null" : r[28]);
I would like to replace a value of -9999 with a blank value as well.
Upvotes: 4
Views: 95
Reputation: 387
You can do it this way:
string.Join(
",",
from
r in siteData.Rows.OfType<DataRow>()
select
string.IsNullOrEmpty((string)r[28]) ? "null" : r[28]);
Upvotes: 0
Reputation: 155628
In SQL, use CASE WHEN
:
SELECT
CASE WHEN someValue = -9999 THEN '' ELSE someValue END AS colName
In Linq, just change your ternary:
siteData.Rows.OfType<DataRow>().Select( r => r[28] == DBNull.Value || r[28] == -9999 ? "" : r[28] )
Upvotes: 6