Reputation: 282
NET code
Public Function dbStringValue(ByVal drw As DataRow, _
ByVal sColumnName As String) As String
If IsDBNull(drw.Item(sColumnName)) Then
dbStringValue = ""
Else
dbStringValue = CType(drw.Item(sColumnName), String)
End If
End Function
now this is part of a clean up code which interrogates a datarow for null values. A datarow is passed along with the column name. I have tried to con vert it to c# as follows
public static string dbStringValue(DataRow drw, string sColumnName)
{
string functionReturnValue = "";
if (drw(sColumnName) != System.DBNull.Value)
{
functionReturnValue = (string)drw(sColumnName);
}
return functionReturnValue;
}
however there is no Item property for the datarow and googling suggest having it as datarow("ColumnName"). Using this method I keep getting drw is a variable but used like a method error.
Can anybody help
Upvotes: 0
Views: 118
Reputation: 282
as soon as I posted this question I noticed its
["ColumnName"]
rather than
("ColumnName")
I have changed this and now it seems to be fine.
Upvotes: 0
Reputation: 11482
datarow["ColumnName"]
is the correct usage, as you have to access the indexer , difference is the C# syntax
Upvotes: 2