2

Using .NET 4 and C#. All of these throw an error:

sdsTypeinfo.SelectParameters.Add("@TypeCode", DbType.Boolean, DBNull.Value);

sdsTypeinfo.SelectParameters.Add("@TypeCode", DBNull.Value);

sdsTypeinfo.SelectParameters.Add("@TypeCode", null);

sdsTypeinfo.SelectParameters.Add("@TypeCode", "");

The error indicates that the procedure is not getting any value at all.

Procedure or function 'Typeinfo' expects parameter '@TypeCode', which was not supplied.

Answer

You don't need the @ in the name of the parameter. This is different than adding parameters when calling the stored procedure using a SqlCommand, in which case you want something like this:

cmd.Parameters.AddWithValue("@TypeCode", DBNull.Value);

Also, DBNull.value is an acceptable parameter in the above, but the accepted NULL value when adding SelectParameters to an SqlDataSource is simply "null".

2
  • 1
    What kind of error does it throw? On the Sql server side or client side? What's exactly the error message? Commented Nov 4, 2011 at 14:27
  • 4
    Is it a typo? The error expects the parameter to be called @pTypeCode and you are passing in @TypeCode... Commented Nov 4, 2011 at 14:41

3 Answers 3

1

There should be an option when adding a parameter to convert empty string to null.

<SelectParameters>
    <asp:ControlParameter ControlID="lstCategories" Name="ProductSubcategoryID" ConvertEmptyStringToNull="true" PropertyName="SelectedValue" />
</SelectParameters>

Since you're using a stored procedure, you'll want to make the parameter optional:

@SomeParm INT = NULL
Sign up to request clarification or add additional context in comments.

Comments

0

you can try like this...

    string x = null;
command.Parameters.AddParameter(
     new SqlParameter("@column", (object)x ?? DBNull.Value);

would give you a parm with a value of DBNull.Value, but

string x = "A String";
command.Parameters.AddParameter(
     new SqlParameter("@column", (object)x ?? DBNull.Value);

Comments

0

In your stored procedure set the parameter to have a value eg

@TypeCode = '' 

or if its an int

@typecode = 1

etc you get the idea.

1 Comment

I have no control over the stored procedure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.