Solved

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

Posted on 2004-09-06
5
1,329 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
5 Comments
 
LVL 12

Accepted Solution

by:
vascov earned 168 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 166 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 166 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now