locked
Ent. Lib 5 DAAB. Optional parameters in stored proc RRS feed

  • Question

  • User1898996857 posted

    Hi guys! Have question bout DAAB:

    I have stored procedure in my database which accepts optional parameters like:

    create procedure MyProc @SomeParam int = 1 as begin
      return N'return some stuff';
    end

    I did not find any way to specify, that parameter is optional.
    I tried to omit parameter, when getting "DbCommand", but got exception when tried to execute it.
    So is there any way to tell "DbCommand" that my parameter is optional?

    Wednesday, June 1, 2011 12:54 PM

Answers

  • User1898996857 posted

    Yes, I can. But in this case parameter would be exactly NULL, but I need it to accept its default value. It seems like there's no way for that, so I'll just keep using old good ADO.NET.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 2, 2011 2:45 AM

All replies

  • User-1322853079 posted

    I guess...you can only send null values to optional parameters in stored procedures.., in your case int cant expect a null value so..,

    so use nullabe int value.., from the .Net code..,

    When u assing null values it takes the default value as mentioned in the stored proc..

    Wednesday, June 1, 2011 11:14 PM
  • User1898996857 posted

    Yes, I can. But in this case parameter would be exactly NULL, but I need it to accept its default value. It seems like there's no way for that, so I'll just keep using old good ADO.NET.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 2, 2011 2:45 AM