获取错误输入字符串的格式不正确。 [英] getting error Input string was not in a correct format.
问题描述
你好朋友我需要一个帮助
i有三层架构
in BEL.cs
hello friend i need one help
i have a three tier architecture
in BEL.cs
public string ID { get; set; }
public string Name { get; set;}
public decimal Salary{get;set;}
在BLL.cs中
in BLL.cs
public string insertdata(BEL objinsertdata)
{
DLL obj = new DLL();
return obj.insertdatadll(objinsertdata);
和DLL.cs
and in DLL.cs
public string insertdatadll(BEL obj)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=master;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("proapmc1", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.VarChar, 22));
cmd.Parameters["@ID"].Value = obj.ID;
cmd.Parameters.Add(new SqlParameter("@Name", SqlDbType.VarChar, 44));
cmd.Parameters["@Name"].Value = obj.Name;
cmd.Parameters.Add(new SqlParameter("@Salary", SqlDbType.Decimal, 7));
cmd.Parameters["@Salary"].Value = obj.Salary;
string str = "";
cmd.Parameters.Add(new SqlParameter("@Error", SqlDbType.VarChar, 34));
cmd.Parameters["@Error"].Direction=ParameterDirection.Output;
cmd.ExecuteNonQuery();
str = (string)cmd.Parameters["@Error"].Value.ToString();
return str;
}
和sql字段我的工资是十进制,varchar(22)是ID,名称也是varchar(33)
但是一旦我运行这个代码,所以我在工资字段中收到错误输入字符串的格式不正确。
请告诉我我哪里错了什么我缺少
and in sql field i have taken decimal in salary , ID in varchar(22), and name also varchar(33)
but once i run this codes so i am getting a error in salary field "Input string was not in a correct format."
please tell me where i am wrong and what i am missing
推荐答案
在行
str = (string)cmd.Parameters["@Error"].Value.ToString();
您将值解析为字符串类型2次。这不会引起任何异常,只会提供一个信息。
是的,你在哪一行得到这个问题?
you are parsing value to string type 2 times. This is not going to raise any exception but just an information.
And yes, on which line you are getting this issue?
这篇关于获取错误输入字符串的格式不正确。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!