|
Subject:
|
insert nulls using a typed dataset
|
|
Posted By:
|
humour
|
Post Date:
|
4/16/2008 2:51:48 AM
|
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
|
|
Reply By:
|
cforsyth
|
Reply Date:
|
4/16/2008 3:45:40 AM
|
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?
|
|
Reply By:
|
humour
|
Reply Date:
|
4/16/2008 4:32:14 AM
|
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.
|
|
Reply By:
|
humour
|
Reply Date:
|
4/16/2008 5:17:24 AM
|
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.
|