向数据库写入数据时,提示 ,输入字符串的格式不正确。

ZHANJUNBIN29 2014-05-10 12:11:55
“/人事管理系统设计”应用程序中的服务器错误。
--------------------------------------------------------------------------------

输入字符串的格式不正确。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.FormatException: 输入字符串的格式不正确。

源错误:


行 49: publicFunction pFunction = new publicFunction();
行 50:
行 51: int intYuanID = int.Parse(Yuan_ID.Value);

行 52: String strYuanName = Yuan_Name.Value;
行 53:
以下是具体代码,求大神帮忙看看哪里出错了

protected void butSave_Click(object sender, EventArgs e)
{
Yuan_RP yuan_rp = new Yuan_RP();
publicFunction pFunction = new publicFunction();

int intYuanID = int.Parse(Yuan_ID.Value);
String strYuanName = Yuan_Name.Value;

int intRPID = int.Parse(RP_ID.Value);
String strRPName = RP_Name.Value;
float strYuanRPValue = float.Parse(RP_Value.Value);

DateTime dtYuanRPDate = DateTime.Parse(Yuan_RP_Date.Value);

DataTable T_Yuan_RP = (DataTable)Session["T_Yuan_RP"];

yuan_rp.Field_Yuan_ID = intYuanID;
yuan_rp.Field_Yuan_Name = strYuanName;
yuan_rp.Field_RP_ID = intRPID;
yuan_rp.Field_RP_Name = strRPName;
yuan_rp.Field_Yuan_RP_Value = strYuanRPValue;
yuan_rp.Field_Yuan_RP_Date = dtYuanRPDate;
yuan_rp.Field_Yuan_RP_YuanY = Yuan_RP_YuanY.Text;
yuan_rp.Field_Yuan_RP_Memo = Yuan_RP_Memo.Text;

if (Hid_Command.Value == "INSERT")
{
String strReturn = yuan_rp.Yuan_RPInsert();
if (strReturn.Contains("ok"))
{
Response.Redirect("YuanRPView.aspx");
}
}
else if (Hid_Command.Value == "UPDATE")
{
yuan_rp.Field_Int_Yuan_RP_ID = int.Parse(T_Yuan_RP.Rows[int.Parse(Hid_RowIndex.Value)]["Yuan_RP_ID"].ToString());
yuan_rp.RowIndex = int.Parse(Hid_RowIndex.Value);
String strReturn = yuan_rp.Yuan_RPUpdate();
if (strReturn.Contains("ok"))
{
Response.Redirect("YuanRPView.aspx");
}
else if (strReturn.Contains("fail"))
{
lbl_Show.Text = strReturn.Replace("fail", "");
}
}
}
protected void butReturn_Click(object sender, EventArgs e)
{
Response.Redirect("YuanRPView.aspx");
}
}
...全文
516 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
oLanJieKou 2014-05-20
  • 打赏
  • 举报
回复
很明显的一个错误 源代码都给出来了 int类型转换失败 这是常见错误
jimil 2014-05-20
  • 打赏
  • 举报
回复
值为非int型,注意int为整型,不带小数点。
rayyu1989 2014-05-19
  • 打赏
  • 举报
回复
用户输入的 Yuan_ID.Value 不是数字 使用 int.TryParse
huhailong520 2014-05-19
  • 打赏
  • 举报
回复
肯定是那个值不是数字,或者为null。关键是那个值是什么!
Astpiy 2014-05-16
  • 打赏
  • 举报
回复
我觉得你的字符窜 不正正确转为int额 ,断点跟踪下 那个字符串的值是什么、
Hertz_liu 2014-05-15
  • 打赏
  • 举报
回复
你Yuan_ID.Value的值肯定不是一个可以转换成int的值,好好检查检查 建议做一些容错处理,如: int intYuanID; if(int.TryParse(Yuan_ID.Value,out intYuanID)){ //do something }else{ //parse failed //do something else }
  • 打赏
  • 举报
回复
int.Parse(Yuan_ID.Value) 这个强制转换是只能把字符串格式转为int型,你的 Yuan_ID.Value可能不是字符串格式

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧