Hello Friends,
I m new in C# programming.
when i access data from a file.
i don't know each field has data or not.
but in my c# coding file wirte code
double value=Convert.ToDouble(dataRow["fieldValue"]);
if fieldValue is null or empty this code show exception.
Please suggest.
Thanks.
Loading

Hirendra SisodiyaRank #258 · 9.8K reputationPosted Mar 17, 2010, 12:18 AM EDT
if (dataRow["fieldValue"] != null)
{
double value = Convert.ToDouble(dataRow["fieldValue"]);
}
else
{
}
thanks
Please Check answere if you like my answere
Amit ChoudharyRank #145 · 15.8K reputationPosted Mar 17, 2010, 1:13 AM EDT
put a condition before using the value:
if(dataRow["fieldValur"]!=DBnull)
{
double value=Convert.ToDouble(dataRow["fieldValue"]);
}
please mark as answer if it helps.
Jitendra Tiwari33 reputationPosted Mar 17, 2010, 5:52 AM EDT
thanks
but my problem like this
excelUserRecord = (from abc in dataRow
where
(listSchemeCode.Contains(abc.Field
|| (listTrnxNo.Contains(Convert.ToString((abc.Field
|| (listFolioNo.Contains((abc.Field
select abc);
if transaction is null form show errorrrr
Sam HobbsRank #107 · 20.5K reputationPosted Mar 17, 2010, 11:03 AM EDT
Jitendra Tiwari33 reputationPosted Mar 17, 2010, 9:30 PM EDT
where
(listSchemeCode.Contains(abc.Field
|| (listTrnxNo.Contains(Convert.ToString((abc.Field
|| (listFolioNo.Contains((abc.Field
select abc);
there is no prob field value is double or string.
problem is that if the value of TransactionNO(Bold in code block) is null linq query throw exception.
when I access each row from data row collection