Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 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 April 16th, 2008, 02:51 AM
Authorized User
 
Join Date: Aug 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to humour
Default insert nulls using a typed dataset

Version 1.1 of my post (edited) based on comments made to improve my posts clarity :-)

I know its out there.................. the answer - but I have tried and tried and tried to find it using seach and I cannot. Undboutedly someone will point me to the answer in another thread or FAQ.

environment: VS 2005, Sql Server Express

Language: vb.net

I have a strongly typed dataset - one created using the dataset designer - I created an INSERT (that works) until I try and insert null values. I want to be able to use a strongly typed dataset and insert null values in DECIMAL, INT, VARCHAR, and DATETIME fields The example I have provided below of things I have tried only apply for a Decimal Column.

The PROPERTY "AllowDBNull" of the paramater of my typed dataset is set to TRUE

Direction of the Paramater is set to INPUT.

What I have tried and does not work..

Method 1 -- doesnt work (casting dbnull.value to a decimal as the paramater) See error message below
todoadapter.InsertIntoToDo( _
        "aaa", _
        "bbb", _
    Convert.ToDecimal(DBNull.Value))

Third column in this example is a decimal error I get it:Value of type system.dbnull cannot be converted to system.nullable (of decimal)

Runtime Error: Object cannot be cast from DBNull to other types

Method 2: Doesn't Work - Using dbnull.value as the paramater See the compile error message below

todoadapter.InsertIntoToDo( _
        "aaa", _
        "bbb", _
DBNull.Value)

Compile Error: Value of type 'System.DBNull' cannot be converted to 'System.Nullable(Of Decimal)'.


Method 3: Doesn't Work - using system.dbnull as a parameter - See the compile error message below.


todoadapter.InsertIntoToDo( _
        "aaa", _
        "bbb", _
system.dbnull)

Compile Error: dbnull is a type in 'system' and cannot be used as an expression.

Any help appreciated strongly.

These forums are great resources by finding the answer in the ocean of answers is sometimes the problem.

Thanks in Advance

Humour
 
Old April 16th, 2008, 03:45 AM
Authorized User
 
Join Date: Oct 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

One sure way to get people to not bother replying to your thread is to describe your problem as "doesn't work" instead of providing the actual and exact error message(s) you get, and the line of code (in context) where it occurs (to the best of your knowledge).

When you visit your doctor do you do the same thing? Do you say just "I hurt" or do you actually take the time to describe your symptoms?

 
Old April 16th, 2008, 04:32 AM
Authorized User
 
Join Date: Aug 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to humour
Default

cforsyth

Re-read my post --- at the bottom of method 1 and 2 I wrote the error message I recieved. I neglected to do it for method 3 (my bad).
I will now edit my post if can.

Thanks for constructive criticism on my post - always room for improvement.
 
Old April 16th, 2008, 05:17 AM
Authorized User
 
Join Date: Aug 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to humour
Default

I got the answer (yes I admit I crossposted it on another forum site) ...

At least I am sharing with the class by posting the solution here:

The way to do it in VB.NET is as follows:

todoadapter.InsertIntoToDo( _
        "aaa", _
        "bbb", _
        Nothing)

Thanks for reading and my sincere hope is others may benefit from the keystokes.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Create new row using a typed dataset humour ASP.NET 2.0 Professional 0 May 9th, 2008 09:49 PM
Converting a untyped dataset to a typed dataset daphnean Visual Studio 2005 0 July 13th, 2006 01:16 AM
How to allow NULLS in a dataset parameter pghodgao BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 3 February 16th, 2006 03:02 PM
What Are Typed Dataset vinod_pawar1 ADO.NET 2 May 13th, 2005 04:52 AM
Dynamic DataAdapter from Typed Dataset dhay1999 ADO.NET 3 May 3rd, 2005 07:07 AM





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