?
Solved

Insert a Null value into a database table using Typed Dataset and Stored Procedure

Posted on 2004-09-06
5
Medium Priority
?
1,348 Views
Last Modified: 2012-08-14
Dear friends a have a  problem!
When I try to insert a record in a table in my database which containes a null value (Empty property of a typed dataset) i get an exception!
 get {
       try {
       return ((System.DateTime)(this[this.tableActivities.LoanStartColumn]));
       }
       catch (InvalidCastException e) {
Does anyboby have a hint?
0
Comment
Question by:a_ro_no
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 12

Accepted Solution

by:
vascov earned 672 total points
ID: 11988075
Use the Set<FieldName>Null method to make the field null.
Ex:
ds.tableActivities.Rows[0].SetLoanStartNull()

Then, make sure that at the DB layer the field is allowed to be null.

hth

Vasco
0
 
LVL 10

Assisted Solution

by:123654789987
123654789987 earned 664 total points
ID: 11988081
U cannot type cast a null field to a dateTime

Try this
s= this[this.tableActivities.LoanStartColumn]);
public static NullableDateTime ToNullableDateTime(string s)
            {
                  if (s == null) return null;

                  if (s.Length == 0) return null;

                  return new NullableDateTime(Convert.ToDateTime(s));
            }

The return value will be of nullabledateTime.

for a normal datetime field u cannot insert null
0
 

Assisted Solution

by:nj_buck
nj_buck earned 664 total points
ID: 11991570
It is prefereable to use a stored procedure for update/inserts.  In Oracle PL/SQL use the NVL function (in T-SQL its Coalesce) to change NULL to the proper value for the database schema.

The insert in the statement could use NVL something like this:

INSERT INTO TABLEA (
       FIELD1,
       FIELD2)
SELECT
       INTVALUE1,
       NVL(DATEVALUE2, 0)
FROM TABLEB
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question