Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all I have a code in VB6 as follows

Dim strLedger as string
VB
Dim rs as Recordset

rs=some execute query

strLedger=IIf(IsNull(rs!Ledger), vbNullString, rs!Ledger)


I converted this to C# as follows

C#
String str=string.Empty;
DataSet ds=new DataSet();
ds=some execute query;
if(ds.Tables[0].Rows[0]["Ledger"].ToString()==string.Empty)
{
str=string.Empty;
}
else
{
str=ds.Tables[0].Rows[0]["Ledger"].ToString();
}


Is this a correct conversion or if any let me know
Posted
Comments
Shubham Choudhary 14-Mar-13 2:40am    
yes its correct!!!

1 solution

To compare for a null value in the database, use is System.DBNull.
vbNullString corresponds to string.Empty.
I'd prefer
C#
if(ds.Tables[0].Rows[0]["Ledger"] is System.DBNull)
{
    str=string.Empty;
}
else
{
   str=ds.Tables[0].Rows[0]["Ledger"].ToString();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900