日期:2014-05-17  浏览次数:20753 次

输入字符串格式不正确,来看看吧,亲!!!!
报错,出现“输入字符串格式不正确”,数据类型格式都对着呢,和数据库也对应!问题是sqlParams[1].Value = int.Parse(this.ViewState["PopedomId"].ToString());取不到值。
代码如下:

 private bool GetMaintainInfo(out string AlertError)
    {
        bool flag = false;
        AlertError = "";
        new SysClass();
        try
        {
            string sQL = " select VehicleType,VehicleTypeID,MaintainCycle,CycleUnit,PopedomId from VehicleType where VehicleType = @VehicleType and PopedomId=@PopedomId";
            SqlParameter[] sqlParams = new SqlParameter[] { 
                new SqlParameter("@VehicleType", SqlDbType.VarChar, 50), 
                new SqlParameter("@PopedomId", SqlDbType.Int) 
            };
            sqlParams[0].Value = this.TextBox4.Text.Trim().ToString();//车辆类型
            //string test0 = this.TextBox4.Text.Trim().ToString();
            sqlParams[1].Value = int.Parse(this.ViewState["PopedomId"].ToString());//错误所在!!!!!!!!!这里的值为空,取不到值。
            //int test = int.Parse(this.ViewState["PopedomId"].ToString());
            DBClass class2 = new DBClass("ConnStr");
            class2.ReadData(sQL, sqlParams);
            while (class2.MyReader.Read())
            {
                this.ViewState["MaintainCycle"] = class2.MyReader["MaintainCycle"];
                this.ViewState["CycleUnit"] = class2.MyReader["CycleUnit"];
                flag = true;
            }
            class2.MyReader.Close();
            class2.MyReader.Dispose();
            class2.Conn.Close();
            class2.Conn.Dispose();
            if (!flag)
            {
                AlertError = "车辆类型【" + this.TextBox4.Text.Trim() + "】未配置";
  &