• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1358
  • Last Modified:

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

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
a_ro_no
Asked:
a_ro_no
3 Solutions
 
vascovCommented:
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
 
123654789987Commented:
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
 
nj_buckCommented:
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now