我在运行程序项目时收到此错误"Server Error in '/' Application. Input string was not in a correct format. "



我在运行程序项目"服务器错误在'/'应用程序中。输入字符串的格式不正确。

第37行:if(Convert.ToInt16(GetPermission)==-1)

   Session["ModuleID"] = "1";
    usrid1 = Convert.ToInt16(Session[SessionHelper.CURRENTID].ToString());
    modid = Convert.ToInt16(Session["ModuleID"].ToString ());
    string GetPermission = DB.Exec_SQL("select Allow_add from UsercontrolMaster where Usrid='" + usrid1 + "' and ModuleID='" + modid + "'");
    if (!IsPostBack)
    {
        if (Convert.ToInt16(GetPermission) == -1)
        {
            if (!IsPostBack)
                //load Control
                if (Session[SessionHelper.OPERATION] == Constant.EDIT && Session[SessionHelper.RECORDID] == null)
                {
                    Response.Redirect("~/User Master/Default.aspx");
                }
            if (Session[SessionHelper.OPERATION] == Constant.EDIT && !IsPostBack)
            {
                Session[SessionHelper.DATA] = bndll._ReturnDatatableNew("select * from Usertable where Usrid ='" + _selectedRecordId + "'"); // Load Data from Data Table
                if (!IsPostBack)
                {
                    filldata();
                }
            }
        }

造成这个问题的原因有很多。对于每个转换函数,转换后的字符串可能为null或不可转换的字符串。因此,当您调用db时,数据可能会返回null。之后,当您将GetPermission转换为int16时抛出异常。

检查您的值并确保您的值是可转换的。

最新更新