I got a function in which I send two requests to a SQL Server database; on the second request however, I get a SqlException
and the parameter @mpe
is missing. If I try to set the constant value 0
in the constructor of SqlParameter
.
protected static string GetX(int mpe, string xsection, string xkey)
{
var xSetup = App.Current.Db.GetType<Data.CachedTypes.XSetup>(
"where mpehotel=@mpe and xsection=@xsection and xkey=@xkey",
new System.Data.SqlClient.SqlParameter("@mpe", mpe),
new System.Data.SqlClient.SqlParameter("@xsection", xsection),
new System.Data.SqlClient.SqlParameter("@xkey", xkey));
if (mpe > 0 && xSetup == null)
{
// Fallback mechanism. Always tries to get the default for all MPEs.
xSetup = App.Current.Db.GetType<Data.CachedTypes.XSetup>(
"where mpehotel=@mpe and xsection=@xsection and xkey=@xkey",
new System.Data.SqlClient.SqlParameter("@mpe", 0), <-- THIS FAILES!!
new System.Data.SqlClient.SqlParameter("@xsection", xsection),
new System.Data.SqlClient.SqlParameter("@xkey", xkey));
However, if I extract the constant value 0
to a local value int xmpe = 0
and pass this to the constructor, the SQL query executes as expected and a result is retrieved. Can someone explain why this happens?