Solved

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

Posted on 2004-09-06
5
1,334 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
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)…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 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