Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Null value trapping on forms driving me mad!


Message #1 by "Charles Emerson" <charles@S...> on Tue, 29 Jan 2002 15:07:19
I am trying to make a simple edit form and populate it unbound from a SQL 

database and am having fits with how to trap null values to keep it from 

blowing up my asp.net form.



' Obtain a single row of document information



Dim Timekeepers As New Billing.TimekeepersDB()

Dim dr As SqlDataReader = Timekeepers.GetSingleTimekeeper(TimekeeperId)



' Load first row into Datareader dr.Read()



txtFirstName.Text = CStr(dr("FirstName"))



This work fine if there's a valid value, but crashes with evil if the 

value is null - how best to code this - it's so easy in Access & VB, but 

I'm ready to jump!



Also, type conversions are most unforgiving - such as money fields or 

boolean checkboxes.



I love the granularity of asp.net, but there's alot of coding to get 

stuff done, and any error blows up the app.



Thanks all.



Charles Emerson

 

 

   

 

Message #2 by "Alvin Ling" <alvin.ling@i...> on Tue, 29 Jan 2002 10:25:51 -0500
Not sure if it's the answer you're looking for but you could process

null values on the DB



SELECT ISNULL(firstname, 'Unknown')

FROM ...



Or if applicable, exclude null values from your query altogether with a

where clause.



Alvin





> -----Original Message-----

> From: Charles Emerson [mailto:charles@S...] 

> Sent: Tuesday, January 29, 2002 3:07 PM

> To: ASP+

> Subject: [aspx] Null value trapping on forms driving me mad!

> 

> 

> I am trying to make a simple edit form and populate it 

> unbound from a SQL 

> database and am having fits with how to trap null values to 

> keep it from 

> blowing up my asp.net form.

> 

> ' Obtain a single row of document information

> 

> Dim Timekeepers As New Billing.TimekeepersDB()

> Dim dr As SqlDataReader = 

> Timekeepers.GetSingleTimekeeper(TimekeeperId)

> 

> ' Load first row into Datareader dr.Read()

> 

> txtFirstName.Text = CStr(dr("FirstName"))

> 

> This work fine if there's a valid value, but crashes with evil if the 

> value is null - how best to code this - it's so easy in 

> Access & VB, but 

> I'm ready to jump!

> 

> Also, type conversions are most unforgiving - such as money fields or 

> boolean checkboxes.

> 

> I love the granularity of asp.net, but there's alot of coding to get 

> stuff done, and any error blows up the app.

> 

> Thanks all.

> 

> Charles Emerson

>  

>  

>    

>  

> 




> 

> 









Message #3 by "Samuel Engelman" <samuel_engelman@p...> on Tue, 29 Jan 2002 10:40:31 -0500
Why don't you try the true and tested txtFirstName.Text = CStr(dr("FirstName" +

""))?





|--------+--------------------------------->

|        |   "Charles Emerson"             |

|        |   <charles@S...>   |

|        |                                 |

|        |                                 |

|        |   Tuesday January 29, 2002 10:07|

|        |   AM                            |

|        |   Please respond to "ASP+"      |

|        |                                 |

|--------+--------------------------------->

  >------------------------------------------------------------|

  |                                                            |

  |      To:                                  "ASP+"           |

  |       <aspx@p...>                                  |

  |      cc:                                                   |

  |      Subject: [aspx] Null value trapping on forms driving  |

  |       me mad!                                              |

  >------------------------------------------------------------|









I am trying to make a simple edit form and populate it unbound from a SQL

database and am having fits with how to trap null values to keep it from

blowing up my asp.net form.



' Obtain a single row of document information



Dim Timekeepers As New Billing.TimekeepersDB()

Dim dr As SqlDataReader = Timekeepers.GetSingleTimekeeper(TimekeeperId)



' Load first row into Datareader dr.Read()



txtFirstName.Text = CStr(dr("FirstName"))



This work fine if there's a valid value, but crashes with evil if the

value is null - how best to code this - it's so easy in Access & VB, but

I'm ready to jump!



Also, type conversions are most unforgiving - such as money fields or

boolean checkboxes.



I love the granularity of asp.net, but there's alot of coding to get

stuff done, and any error blows up the app.



Thanks all.



Charles Emerson




















Message #4 by ToddC@m... on Tue, 29 Jan 2002 10:48:01 -0600
Or just stop creating fields that allow nulls.  Just default them to empty

string or 0.  Nulls require special handling for DB server and the

Programmer, and the end user doesn't give a damn.



Tc



Keep it lean and fast.



-----Original Message-----

From: Alvin Ling [mailto:alvin.ling@i...] 

Sent: Tuesday, January 29, 2002 9:26 AM

To: ASP+

Subject: [aspx] RE: Null value trapping on forms driving me mad!



Not sure if it's the answer you're looking for but you could process

null values on the DB



SELECT ISNULL(firstname, 'Unknown')

FROM ...



Or if applicable, exclude null values from your query altogether with a

where clause.



Alvin





> -----Original Message-----

> From: Charles Emerson [mailto:charles@S...] 

> Sent: Tuesday, January 29, 2002 3:07 PM

> To: ASP+

> Subject: [aspx] Null value trapping on forms driving me mad!

> 

> 

> I am trying to make a simple edit form and populate it 

> unbound from a SQL 

> database and am having fits with how to trap null values to 

> keep it from 

> blowing up my asp.net form.

> 

> ' Obtain a single row of document information

> 

> Dim Timekeepers As New Billing.TimekeepersDB()

> Dim dr As SqlDataReader = 

> Timekeepers.GetSingleTimekeeper(TimekeeperId)

> 

> ' Load first row into Datareader dr.Read()

> 

> txtFirstName.Text = CStr(dr("FirstName"))

> 

> This work fine if there's a valid value, but crashes with evil if the 

> value is null - how best to code this - it's so easy in 

> Access & VB, but 

> I'm ready to jump!

> 

> Also, type conversions are most unforgiving - such as money fields or 

> boolean checkboxes.

> 

> I love the granularity of asp.net, but there's alot of coding to get 

> stuff done, and any error blows up the app.

> 

> Thanks all.

> 

> Charles Emerson

>  

>  

>    

>  

> 




> 

> 















  Return to Index