首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

输入字符串格式不正确,该怎么解决

2012-07-28 
输入字符串格式不正确[codeC#][/code]protected void Button_Save_Click(object sender, EventArgs e){if

输入字符串格式不正确
[code=C#][/code]protected void Button_Save_Click(object sender, EventArgs e)
  {
  if (Page.IsValid)
  {
  try
  {
  Tab_ProductEnti productenti = new Tab_ProductEnti();
  productenti.ProductTitle = this.txtproductTitle.Text;
  productenti.DefaultPic = this.txtDefaultPic.Text;
  int parentID = int.Parse(this.hfParent.Value.ToString());
  productenti.NumberID = this.txtnumberid.Text;
  if (parentID == 0)
  {
  PageInfo("请选择商标类型再添加内容", "Product_Add.aspx");
  return;
  }
  productenti.ParentID = parentID;
  productenti.OrderID = int.Parse(txtorderid.Text.Trim());
  productenti.KeyWord = txtkeyword.Text;
  productenti.Content = this.FCKeditor1.Value;
  productenti.Price = int.Parse(this.txtprice.Text);
  productenti.Description = this.txtDescription.Text;
  productenti.AddTime = DateTime.Now;
  productenti.BeginTime = DateTime.Parse(txtbegintime.Text);
  productenti.IsPass = ckIsPass.Checked;
  productenti.IsRed = isred.Checked;
  productenti.IsSpe = isspe.Checked;
  productenti.Itsown = itsown.Checked;
  productenti.BrandID = int.Parse(lanmu.SelectedValue);

  if (((Button)sender).Text == "保存")
  {
  string savePath = "Product/" + GetClassDirectory(parentID.ToString()) + "/" + DirFile.GetDateDir() + "/";
  string fileName = DirFile.GetDateFile();
  string fileEXName = ".html";
  productenti.SavePath = savePath;
  productenti.FileName = fileName;
  productenti.FileExName = fileEXName;
  if (Tab_Product.Add(productenti) == 1)
  {
  CreateHmtl(productenti);
  PageInfo("添加成功", "Product_List.aspx");
  }
  else
  {
  PageInfo("添加失败", "Product_Add.aspx");
  }
  }
  else if (((Button)sender).Text == "保存修改")
  {
  string ID = Request.QueryString["ID"];
  productenti.SavePath = ViewState["SavePath"].ToString();
  productenti.FileName = ViewState["FileName"].ToString();
  productenti.FileExName = ViewState["FileExName"].ToString();
  if (ID == null || ID.Equals(""))
  {
  PageInfo("参数错误", "Product_List.aspx");
  }
  else
  {
  productenti.ID = int.Parse(ID);
  if (Tab_Product.Edit(productenti) == 1)
  {


  CreateHmtl(productenti);
  PageInfo("修改成功", "Product_List.aspx");
  }
  else
  {
  PageInfo("修改失败", "Product_List.aspx");
  }
  }
  }
  }
  catch (Exception ex)
  {
  log.Error(ex.Message);
  }
  }
  }

[解决办法]
哪句出错了
[解决办法]
int.Parse DateTime.Parse 很危险啊
[解决办法]
把错误提示信息贴出来撒!
[解决办法]
log.Error(ex.Message);
换成
log.Error(ex.ToString());
[解决办法]
this.hfParent.Value
txtorderid.Text
this.txtprice
txtbegintime.Text
lanmu.SelectedValue
ID
出错时你检查下上面这些的值分别是什么,贴上来最好
[解决办法]
看日志,定位错误行
[解决办法]
一步步执行,看看是那句代码报错,然后跳到错误catch中了
你代码中确实用了很多 Parse 相关的,这个你要不做判断,最有可能出错的就是他,当数据不能被转换为目标类型是就会出错了
[解决办法]
你先把方法里的 try catch 去掉,然后再调试,等到报错,看出在哪行上

热点排行