PC Review


Reply
Thread Tools Rate Thread

How to check for query field length

 
 
=?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=
Guest
Posts: n/a
 
      27th Jan 2005
I have the follow asignment: txtDescription.Text = dtrSlb("slbDesc2")
If the field returned is Null i get a run time error.
I can check for if (dtrSlb("slbDesc1").GetType.ToString() = "System.DBNull")
then .... But there has to be a better way.
Aslo what's the best way t oget the length of the returned field from a query?
Thanks for help on this simple question
kes
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      27th Jan 2005
Hi,

In VB.NET you can use IsDBNull function, or generally Convert.IsDBNull to
check if it is DBNull or if working with DataReader then its own IsDbNull
method.

You could create general class for the mostly used types to convert it to
certain type and check for null. For example NZ.GetString(argument) which
returns String.Empty if argument is DBNull and otherwise return the value
converted to string. You could pass fields straight from DataReader or
DataSet to this method to perform the conversion for UI.

--
Teemu Keiski
ASP.NET MVP, Finland

"Kurt Schroeder" <(E-Mail Removed)> wrote in message
news:0A439DCD-1A9A-498D-908A-(E-Mail Removed)...
> I have the follow asignment: txtDescription.Text =
> dtrSlb("slbDesc2")
> If the field returned is Null i get a run time error.
> I can check for if (dtrSlb("slbDesc1").GetType.ToString() =
> "System.DBNull")
> then .... But there has to be a better way.
> Aslo what's the best way t oget the length of the returned field from a
> query?
> Thanks for help on this simple question
> kes



 
Reply With Quote
 
=?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=
Guest
Posts: n/a
 
      27th Jan 2005
thank you that's it!!!!!
kes

"Teemu Keiski" wrote:

> Hi,
>
> In VB.NET you can use IsDBNull function, or generally Convert.IsDBNull to
> check if it is DBNull or if working with DataReader then its own IsDbNull
> method.
>
> You could create general class for the mostly used types to convert it to
> certain type and check for null. For example NZ.GetString(argument) which
> returns String.Empty if argument is DBNull and otherwise return the value
> converted to string. You could pass fields straight from DataReader or
> DataSet to this method to perform the conversion for UI.
>
> --
> Teemu Keiski
> ASP.NET MVP, Finland
>
> "Kurt Schroeder" <(E-Mail Removed)> wrote in message
> news:0A439DCD-1A9A-498D-908A-(E-Mail Removed)...
> > I have the follow asignment: txtDescription.Text =
> > dtrSlb("slbDesc2")
> > If the field returned is Null i get a run time error.
> > I can check for if (dtrSlb("slbDesc1").GetType.ToString() =
> > "System.DBNull")
> > then .... But there has to be a better way.
> > Aslo what's the best way t oget the length of the returned field from a
> > query?
> > Thanks for help on this simple question
> > kes

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Query -Maximum Field Length RayToddJr Microsoft Access Queries 2 18th Sep 2009 06:44 PM
Count field length in delimeted file and compare with predefined listof field length Ixtreme Microsoft Access 8 18th Mar 2009 01:10 PM
Query field length??? Rohn Microsoft Access Queries 6 24th Apr 2004 09:45 PM
How can I check the length of a Field in a Table Sajid Microsoft Dot NET 2 10th Apr 2004 07:26 PM
Best way to check minimum length for a textbox field Abhishek Srivastava Microsoft ASP .NET 2 10th Feb 2004 02:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:41 AM.