Field to String error

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.
 
J

John Saunders

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.
 
B

Ben

You need to test the field for null first.

In c# it would look like

if (dataobject != DBNull.Value)
{

}
 

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

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top