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

edosoft
  • 17,121
  • 25
  • 77
  • 111
WtFudgE
  • 5,080
  • 7
  • 47
  • 59

2 Answers2

4

Have you tried:

DBNull.Value
cjk
  • 45,739
  • 9
  • 81
  • 112
1

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

edosoft
  • 17,121
  • 25
  • 77
  • 111