Field to String error

  • Thread starter Thread starter jlmjrdev
  • Start date Start date
J

jlmjrdev

I am new to asp.net. In classic asp, I would often test a return
value from a stored proc against ""(blank). I am always getting this
error in asp.net - "Cast from type 'Field' to type 'String' is not
valid".

Why am I getting this error? I want to check to see if something is
null or blank, and I'm always getting this error. Help please.
 
jlmjrdev said:
I am new to asp.net. In classic asp, I would often test a return
value from a stored proc against ""(blank). I am always getting this
error in asp.net - "Cast from type 'Field' to type 'String' is not
valid".

Why am I getting this error? I want to check to see if something is
null or blank, and I'm always getting this error. Help please.

I would suggest that you stop using ADO and learn to use ADO.NET.

I would also suggest that you set Options Strict at the beginning of your
scripts. That way, the compiler will tell you what you're doing wrong.

In particular, the type "Field" is not the same thing as a "String".
VBScript in ASP allowed you to get away with that at the expense of doing
conversions behind your back.
 
You need to test the field for null first.

In c# it would look like

if (dataobject != DBNull.Value)
{

}
 
Back
Top