Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

914 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

15 Experts available now in Live!

Get 1:1 Help Now