I have written the following code:
Dim E_ID As Integer
E_ID = Convert.ToInt16(Request.QueryString("ID"))
But when it executes, I always get a FormatException
:
error: Input string was not in a correct format.
What could be causing this?
i am sending value like this.
Protected Sub lnkPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkPrint.Click
lnkPrint.Attributes.Add("onclick", "return openBadgeReportPage('" + ddEvent.DataValueField + "','" + ddType.DataValueField + "')")
End Sub
End Class
Because whatever value is being returned by the
Request.QueryString("ID")
function call is not convertible to anInt16
type. According to the documentation for theConvert.ToInt16
method, aFormatException
is thrown whenever the:You can see what value is actually being returned by separating your code out into a couple of different lines, and setting a breakpoint. For example: