首页 > 解决方案 > 我没有使用 request.QueryString 从 sql 数据中获取值

问题描述

我正在使用 asp.net webform & C# 以及 SQL 创建一个简单的页面。请看一下代码,这将更容易理解

 public string settype;
         int qid;

settype = System.Convert.ToString(Request.QueryString["settype"]);
qid = System.Convert.ToInt16(Request.QueryString["qid"]); 

有一个带有 settype 和 qid 的表,使用上面的代码我得到了 settype 值,但我无法得到 qid 的值。它保持为空。我错过了什么吗?

sql 中 qid 的数据类型是 numeric(18,0)

标签: c#asp.netwebforms

解决方案


Before fetching the QueryString value we have to check the null condition it is best practices. Below the code 
decimal qid=0.0M;
 if (!string.IsNullOrEmpty(Request.QueryString["qid"]))
          qid= Convert.ToDecimal(Request.QueryString["qid"])

推荐阅读