C # ExecuteQuery null

I have a 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 that it just doesn't use them.

Now using strings 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 does not work, gives an error:

System.Exception error: The request parameter cannot be of type System.Object.

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

Has anyone encountered this problem and found a workaround?

Thanks a bunch

+2
source share
2 answers

You tried:

 DBNull.Value 
+4
source

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

+1
source

Source: https://habr.com/ru/post/1395566/


All Articles