Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Assign null value to integer sql parameter?

$
0
0

Hello guys

So this is my problem, I have a drop down with values from the database it is also has the option to select none of the values "--Select--"

ddlWinders.Items.Insert(0, new ListItem("--Select--", ""));

and this is the sql parameter definition:

 cmd.Parameters.Add("@tubeEndingId", SqlDbType.Int).Value = ddlWinders.SelectedValue

Now when I select the "--Select--" item The obvious thing that happens: System.FormatException: Failed to convert parameter value from a String to a Int32
that is understandable, but I also tried this:

cmd.Parameters.Add("@winderId", SqlDbType.Int).Value = (object)ddlWinders.SelectedValue ?? DBNull.Value;

and the same error pops up which also kind of understandable, So what is the solution.

HELP PLEASE

Thanks


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>