Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: IsDBNull


Message #1 by peter@i... on Tue, 19 Nov 2002 02:06:14
Hmmm, is it?? Because of quite a lot of overhead, Try .. Catch should 
only be used for true errors, not for cases you can check otherwise, 
AFAIK.

Can't you just use:

if (cmd.ExecuteScalar() == DBNull.Value)

?

HtH

Imar



> Hello Peter

1) something like this:
While reader.Read()
	If IsDbNull(reader("your_Column_name")) Then
		Response.Write("Column is null")
	Else
		Response.Write(reader("your_Column_name"))
	End If
End While

2) it's best to nest cmd.ExecuteScalar in a try/catch statement;

Try
	cmd.ExecuteScalar()
Catch(Ex as Exception)
	//code to display error, eg
	Response.Write(Ex.GetBaseException().ToString())
End Try

Hope this helps

Phil

-----Original Message-----
From: peter@i... [mailto:peter@i...]
Sent: 19 November 2002 02:06
To: ASPX_Professional
Subject: [aspx_professional] IsDBNull


Hi folks,

A couple of things please:

1. With reader.IsDBNull(0) - is there a way of doing the same but with 
using
the field name (instead of a column ordinal)?
        I mean what happens if I add another field to my select statement?


2. How do I test for null with cmd.ExecuteScalar()?
        This does not work:
            if (cmd.ExecuteScalar() == null)


Thanks
Pete

---
Change your mail options at http://p2p.wrox.com/manager.asp or 
to unsubscribe send a blank email to


  Return to Index