Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inserting a null value via strongly typed dataset

Status
Not open for further replies.

humour

Programmer
Nov 24, 2003
87
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 in vs2005 - I created an INSERT (that works) until I try and insert null values. <b>I want to be able to use a strongly typed dataset and insert null values in DECIMAL, INT, VARCHAR, and DATETIME fields</b> 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)

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)

Error: Value of type system.dbnull cannot be converted to system.nullable (of decimal)

Method 2: Doesn't Work - Using dbnull.value as the paramater

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



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


Method 3: Doesn't Work - using system.dbnull as a paramater

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

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
 
Have you tried

todoadapter.InsertIntoToDo( _
"aaa", _
"bbb", _
"NULL")
?
Change NULL with other string if necessary (should check the sql express docs).
 
Mansii said --
Have you tried
todoadapter.InsertIntoToDo( _
"aaa", _
"bbb", _
"NULL")
------------------------------
No I haven't as I just got a solution from another forum.

The magic answer if your using VB.NET is:
todoadapter.InsertIntoToDo( _
"aaa", _
"bbb", _
NOTHING)

Thanks for your attempt at helping, much appreciated.

Humour
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top