Wrox Programmer Forums
| 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 December 10th, 2004, 03:14 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Mentiri, Muara, Brunei.
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default Comparing DBNull

Hello,

  I have a table with two fields
brand_code Text(2) PK
brand_name Varchar(20)

Brand_code is generated automatically. If no records are there in the table the new brand_code will be "01"

else right("00" & max(brand_code)+1,2)

select max(convert(integer,brand_code)) from brands

How can i read the value? I tried with Sqldatareader
dr=cmd.executereader()

How can i know whether it has retrieved any rows or not.
If i run this query from SQLQueryAnalyzer it returns a row with NULL coz no records initially.
How can i read that value?

Thanx in advance

 
Old December 10th, 2004, 11:13 AM
Authorized User
 
Join Date: Nov 2004
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If i understand your problem the following should solve it:

int barCode;
object temp = cmd.ExecuteScalar();
if(temp==null)
    barCode=1;
else
    barCode = ((int)temp)+1;




Similar Threads
Thread Thread Starter Forum Replies Last Post
The DBNull Class and IsDBNull Function dschnedar BOOK: Professional Visual Basic 2008 ISBN: 978-0-470-19136-1 1 September 27th, 2008 09:13 AM
Convert DBNull to String GailCG ASP.NET 2.0 Basics 1 November 21st, 2006 02:16 AM
String="" convert to DBNull bekim ASP.NET 1.0 and 1.1 Basics 1 February 28th, 2006 01:28 AM
How to Check DBNull while binding controls narendra_patil General .NET 6 May 13th, 2005 07:20 AM
Dealing with DBNull jaucourt VB.NET 2002/2003 Basics 3 January 16th, 2004 10:59 AM





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