Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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
 
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

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

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


 
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....:)






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





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