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.
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] )
You can do it this way:
string.Join(
",",
from
r in siteData.Rows.OfType<DataRow>()
select
string.IsNullOrEmpty((string)r[28]) ? "null" : r[28]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.