Reputation: 1342
The following conversion doesn't work.
Error:"Only assignment, call, increment, decrement & new object can be used as a statement"
VB.net
objUser.Email = IIf(IsDBNull(drow("Email")), "", drow("Email"))
C#
objUser.Email == (Information.IsDBNull(drow("Email")) ? "" : drow("Email"));
I need it in C#. Any ideas??
Upvotes: 0
Views: 2695
Reputation: 48550
In C# =
is asignment operator and ==
is comparison operator
Remove ==
and replace with =
.
Assuming that drow
is DataRow
objUser.Email = (drow.IsNull("Email") ? String.Empty : drow["Email"].ToString());
?:
is ternary operator which always returns a value. In your case that value is being assigned to objUser.Email
.
Upvotes: 3
Reputation: 11287
Try this:
objUser.Email = (DBNull.Value == drow("Email")) ? "" : drow("Email"));
See the Documentation for DbNull - where you will find examples:
From MSDN
private string AddFieldValue(string label, DataRow row,
string fieldName)
{
if (! DBNull.Value.Equals(row[fieldName]))
return (string) row[fieldName] + " ";
else
return String.Empty;
}
Upvotes: 1
Reputation: 959
You're using equal operator instead of assignment operator in the C# variant.
Change the ==
to =
since what you want is assignment.
objUser.Email = (Information.IsDBNull(drow("Email")) ? "" : drow("Email"));
Upvotes: 1
Reputation: 20585
You have accidentally, used comparison operator instead of assignment operator.
objUser.Email == (Information.IsDBNull(drow("Email")) ? "" : drow("Email"));
should be, as you are not doing comparision, its an assignment.
objUser.Email = (Information.IsDBNull(drow("Email")) ? "" : drow("Email"));
Upvotes: 1