ADO .Net performance question

  • Thread starter Thread starter B.M
  • Start date Start date
B

B.M

Hi,

Is there any difference on performance point of view ?

between
String s = MyDataRow["aField"].ToString()

and
String s = (string)MyDataRow["aField"]

The seconde returns a typecast exception if my column is NULL, is there any
best practice about reading string fields ?

Thank you
 
Dunno about performance issue for sure - I suspect there might be a
performance hit if the cast coercion is using the IConvertible interface...
ToString() would be more efficient in such a case...

FYI: You can avoid the DBNull exception by doing this {syntax may not
compile exactly - I'm typing it here for example only...}:

string s = MyDataRow["aField"] as string;
if (s != null)
{
....
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top