Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional 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 September 3rd, 2003, 10:50 AM
Authorized User
Join Date: Aug 2003
Location: , , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default setting DBNull to a string in a dataset at runtime

I have a dataset that I populate from a database. The dataset has 4 columns, and cells in each column hold a string. one of the columns is set as primary key. Some cells in other 3 columns have NULL values (system.DBNull). Here is my problem:

At runtime, I want to be able to assign a string to a cell which previously held a NULL. if I do something like

if ds.tables(0).Rows(someRunTimeIndexValue).Item(1-3) is System.DbNull.Value then
    ds.tables(0).Rows(someRunTimeIndexValue).Item(1-3) = myString
end if

it complains about not being able to convert my string to Int32.

I tried setting the datatype of the columns to string, but it wouldn't let me do that once the dataset has data. I know that my columns are not holding integer values. However, string that I'm trying to assign to a cell is a string representation of a 13 digit number.

Any help will be appreciated.


Old September 3rd, 2003, 03:38 PM
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

Here's one thing you could do. Are you using SQL to fill this dataset? If so, then you can write the SQL statement to handle the cases directly. Use the ISNULL function. So a sample statement would be...

SELECT FieldThatWontBeNULL, ISNULL(FieldThatMightBeNULL,'Null Replacement') FROM MyTable

Then your dataset doesn't need to worry about this. If you need to set this replacement value dynamically, you can just build it into your SQL statement if you are building as a string, or set it up as a parameter if you're going via a stored procedure.

If you still need help, let us know.

Old September 3rd, 2003, 04:28 PM
Authorized User
Join Date: Aug 2003
Location: , , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts

Peter, That worked. Thanks a bunch again


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection String setting at runtime TwoTrees BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 3 July 2nd, 2010 11:41 AM
Conversion from type 'DBNull' to type 'String' is GailCG ASP.NET 2.0 Basics 5 February 22nd, 2007 03:12 PM
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

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