我如何摆脱这个错误:: System.FormatException:输入字符串格式不正确。 [英] how do i come out of this error:: System.FormatException: Input string was not in a correct format.

查看:99
本文介绍了我如何摆脱这个错误:: System.FormatException:输入字符串格式不正确。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Windows Server 2008r2服务器,当我在我的机器上运行应用程序时,它会显示此错误:

I am using windows server 2008r2 server and when i run the application in my machine it shows up this error:

Line 43:             UserBL userBL = new UserBL();
Line 44:             Response.Write(Environment.UserName);
Error line:Line 45:  userBL.PSNo = Convert.ToInt64(Environment.UserName);
Line 46:             //userBL.PSNo = Convert.ToInt64(10604474);
Line 47:             //userBL.Password = ctrLogin.Password;



但该应用程序适用于windows xp机器。

请帮助我纠正这个环境。用户名错误。

提前谢谢


but the application works fine with windows xp machine.
pls help me out to correct this environment.username error.
thanks in advance

推荐答案

输入字符串不正确格式。

很明显。您正在尝试将某些数据转换为不正确的数据类型。



根据您提到的行,这意味着用户名不是 Int64 类型。此外,AFAIK, Environment.Username 的类型为 String 。因此,当您尝试将其转换为 Int64 时,会出现错误。这是一个字符串,而不是一个整数。



参考: MSDN:Environment.UserName属性 [ ^ ]
Input string was not in a correct format.
It''s pretty clear. You are trying to convert some data into a datatype that is incorrect.

Based on the line you mention, this means that username is not of type Int64. Further, AFAIK, Environment.Username is of type String. Thus, when you try to convert it into Int64, you get an error. It''s a string, not an integer.

Refer: MSDN: Environment.UserName Property [^]


这篇关于我如何摆脱这个错误:: System.FormatException:输入字符串格式不正确。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆