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

Posted on 2004-09-06
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?
Question by:a_ro_no
LVL 12

Accepted Solution

vascov earned 168 total points
ID: 11988075
Use the Set<FieldName>Null method to make the field null.

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


LVL 10

Assisted Solution

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

Assisted Solution

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:

       NVL(DATEVALUE2, 0)

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Offline Apllication 5 72
compare between entities in entity framework 8 74
VB.Net Tranfer data between to VB.Net apps 8 26
Call Controller Action Method from ASPX 2 15
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 …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

803 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