I want to do this in "ToString" c#

  • Thread starter Thread starter trint
  • Start date Start date
T

trint

Here is the vb.net version of what I need to do in c#:
myString = drSQL.Item("columnName").ToString()

Thanks,
Trint
 
I see no syntactic problem except missing ";" and undeclared variable

string myString = drSQL.Item("columnName").ToString();
 
well, I get this error though:
(542): 'System.Data.SqlClient.SqlDataReader' does not contain a
definition for 'Item'
 
SqlDataReader.Item is what is known as an indexer in C#. The syntax
should be:

myString = drSQL["columnName"].ToString();

Indexers are supposed to make the code prettier, but most of the time
these kinds of syntactic sugar just makes the code more confusing.

Regards,
Joakim
 
trint said:
Here is the vb.net version of what I need to do in c#:
myString = drSQL.Item("columnName").ToString()

Perhaps you should be writing:
myString = drSQL["columnName"].ToString();

If drSQL is a DataRow.
 
Back
Top