views:

230

answers:

2

I have some code:

using (OAZISDBDataContext ctx = new OAZISDBDataContext())
            {                    
                IEnumerable<DBContactDetail> details = ctx.ExecuteQuery<DBContactDetail>("exec [dbo].[zna_contact] {0}, {1}",
                    "test", "19601023",
             }

However I also want to be able to pass empty values to the stored procedure so it just doesn't use them.

Now with strings this is easy, I can just pass String.Empty and it will work. However if I want to pass empty dates this is a problem.

I obviously tried:

using (OAZISDBDataContext ctx = new OAZISDBDataContext())
            {                    
                IEnumerable<DBContactDetail> details = ctx.ExecuteQuery<DBContactDetail>("exec [dbo].[zna_contact] {0}, {1}",
                    "test", null,
             }

But this doesn't' work, gives the error:

System.Exception: A queryparameter can't be of type System.Object.

After some reading I found out that the ExecuteCommand does not support null parameters while the spec asserts that it should.

Has anybody encountered this issue and found a workaround?

Thanks a bunch

+2  A: 

Have you tried:

DBNull.Value
ck
+1  A: 

Have you tried sending DBNull.Value or new Nullable<DateTime>() ?

edosoft