Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello friend i need one help
i have a three tier architecture
in BEL.cs
C#
public string ID { get; set; }
public string Name { get; set;}
public decimal Salary{get;set;}

in BLL.cs
C#
public string insertdata(BEL objinsertdata)
      {
          DLL obj = new DLL();
         return obj.insertdatadll(objinsertdata);

and in DLL.cs
C#
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;
       }

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
Posted
Updated 20-Dec-14 8:20am
v2
Comments
Afzaal Ahmad Zeeshan 20-Dec-14 14:11pm    
On which line are you getting the error?

1 solution

In line
str = (string)cmd.Parameters["@Error"].Value.ToString();

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?
 
Share this answer
 
Comments
faizyab 2009 20-Dec-14 14:38pm    
problem is coming in this
obj.Salary = Convert.ToDecimal(TextBox3.Text);
control is not going ahead after reaching this section
SK Yadav 20-Dec-14 23:15pm    
This line is not in the above given code. With the limited code you have provided here this error must be coming when the type of Salary is not correctly declared in obj. Please check the type of SALARY in obj.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900