Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 21st, 2005, 05:13 AM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Check DBNull while binding controls

Hello,

I have fetched records in dataset and now i want to bind controls with the dataset but it shows "cannot convert DBNull to "" string"

How to check whether value is Null? WHether i have to check every row is DBNUll or there is any other option?

Thanks...
Narendra
Reply With Quote
  #2 (permalink)  
Old April 21st, 2005, 09:08 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: India.
Posts: 224
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to ashu_from_india Send a message via Yahoo to ashu_from_india
Default


u can check Null value in ur Select statement

SELECT IsNull(FieldName1,0), IsNull(FieldName2,' ') FROM TableName

i hope it will help

Ashu

Reply With Quote
  #3 (permalink)  
Old April 21st, 2005, 10:18 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

As an alternative, you could create a function that always returns a valid string.
I have a function called GetDBString():

public static string GetDBString(object obj) {
    if(!(obj is DBNull)) {
        return (string)obj;
    }
    else {
        return string.Empty;
    }
}

-Peter
Reply With Quote
  #4 (permalink)  
Old April 22nd, 2005, 02:36 AM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I want all records with Primary key whether value is null or not and already filled a dataset with those records but now i want to use taht dataset to fill up the controls irrespective of Null value(If Null then "")...but while setting
like
txtrecNo.text = ds.tables(0)rows(0)(1)

it gives error if ds.tables(0)rows(0)(1) is null....

is there any check????

Thanks for reply....
Narendra

Reply With Quote
  #5 (permalink)  
Old April 22nd, 2005, 10:00 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Are the answers above not enough?

The first answer outlines how to correct null values in the database.
The second provides a server function to handle it.

-Peter
Reply With Quote
  #6 (permalink)  
Old April 23rd, 2005, 12:59 AM
Authorized User
 
Join Date: Nov 2004
Location: Indore, MP, India.
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to avanishp
Default

Hi
 You can use txtrecNo.text = ds.tables(0)rows(0)(1).ToString()

tostring will convert null to blank string.


Reply With Quote
  #7 (permalink)  
Old May 13th, 2005, 07:20 AM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank U all....:)


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding properties to controls pauliehaha ASP.NET 3.5 Basics 0 June 23rd, 2008 04:56 AM
Binding Controls zulf Infopath 0 October 8th, 2007 11:22 PM
Data binding a check box badgolfer VB.NET 2002/2003 Basics 9 July 20th, 2007 02:15 PM
Binding controls Boris Kofman VB Databases Basics 1 January 20th, 2007 01:16 PM
Problems with binding the DateTimePicker controls. mmwaikar ADO.NET 2 November 28th, 2004 03:09 AM



All times are GMT -4. The time now is 04:50 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.