How to test if an ado field is null

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

Need help converting vb.net 1.1 code snippet to c# 2.0.

The code below tests to see if field in a strongly typed data row is null.
This works in vb.net 1.1, but I'm having trouble converting it to c# 2.0
partly because I'm new to c# and also because I'm new to 2.0.

Thanks.

If dr.IsEq_NotesNull Then
cmd.Parameters("@Eq_Notes").Value = dr.IsNull("Eq_Notes")
Else
cmd.Parameters("@Eq_Notes").Value = dr.Eq_Notes
End If
 
How about this?

if (dr.IsEq_NotesNull)
{
cmd.Parameters("@Eq_Notes").Value = dr.IsNull("Eq_Notes");
}
else
{
cmd.Parameters("@Eq_Notes").Value = dr.Eq_Notes;
}
 
You can also try
dr.iSeQ_NotesNull ? cmd.Parameters["@Eq_Notes"].Value =
dr.IsNull("Eq_Notes") : cmd.Parameters["@Eq_Notes"].Value = dr.Eq_Notes;

same as

iif(dr.IsEq_NotesNull, cmd.Parameters("@Eq_Notes").Value =
dr.IsNull("Eq_Notes") , cmd.Parameters("@Eq_Notes").Value = dr.Eq_Notes)

A little more compact

If you need to convert anything else try
http://carlosag.net/Tools/CodeTranslator/Default.aspx, this website will
allow you to translate from VB to C# for free.

Jamie
 
Back
Top