Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
here i have five columns in Employee Named{ Id,Name,Department Id,Location,Salary} and my requirement is to find the details of the Employee based on Id Column when we enter the id in the texbox we should be able to display the Name,Department Id,Location,Salary in the rest of the textboxes.

i have tried the one and written the code as followed in the data access layer

C#
public void findrecord(clsbo objbo)
           {
               try
               {
                con.Open();
                SqlCommand cmd = new SqlCommand("search_tblEmployee ", con);
                cmd.CommandType = CommandType.StoredProcedure;  
                cmd.Parameters.AddWithValue("@Name", objbo._Name);
                cmd.Parameters.AddWithValue("@DepartmentId", objbo._DepartmentId);
                cmd.Parameters.AddWithValue("@Location", objbo._Location);
                cmd.Parameters.AddWithValue("@Salary", objbo._Salary);    


               }
               catch (Exception ex)
               {
                   throw ex;
               }
               finally
               {
                   con.Close();
               } 
In presentation layer code behind 

 protected void btnfind_Click(object sender, EventArgs e)
        {
            try
            {
                clsbo objbo = new clsbo();
                clsbll objbll = new clsbll();
                objbo._Id = Convert.ToInt32(txtid.Text);
                objbo._Name = txtname.Text;
                objbo._DepartmentId = Convert.ToInt32(txtdepartmentid.Text);
                objbo._Salary = Convert.ToInt32(txtsalary.Text);
                objbo._Location = txtlocation.Text;
                objbll.FindRecord(objbo);
                Label1.Text = "Record Found";
            }
            catch (Exception ex)
            {
                throw ex;
            }

and business Logic layer

C#
public void FindRecord(clsbo objbo)
       {
           clsdal objdal = new clsdal();
           try
           {
               objdal.findrecord(objbo);
           }
           catch(Exception ex)
           {
               throw ex;
           }


but when i enter id in the textbox i'am getting the error as

C#
Input string was not in a correct format.

Help me Out Thanks in Advance
Posted
Updated 18-Apr-14 20:00pm
v4
Comments
Sergey Alexandrovich Kryukov 19-Apr-14 1:02am    
This is total garbage; just remove it:

catch (Exception ex)
{
throw ex;
}

—SA
Bh@gyesh 19-Apr-14 1:09am    
Hi,
In code --> in "btnfind_Click" event, you are actually inserting records in table not (objbll.insertrecord(objbo)) finding is it right code?
raxhemanth 19-Apr-14 1:33am    
what is the code to find the record can you please modify my code please
Bh@gyesh 19-Apr-14 2:00am    
Replace line "objbll.insertrecord(objbo);" with "objbll.FindRecord(objbo);. It may be solve your problem.

1 solution

Please try is as below.

Replace objbo._Id = Convert.ToInt32(txtid.Text); with
C#
if(Int32.TryParse(txtid.Text, out int result)) {
     objbo._Id =  result;
}


Read this for more info : Int32.TryParse Method (String, Int32)
 
Share this answer
 
Comments
raxhemanth 19-Apr-14 4:07am    
still getting same error for DepartmentId column
Sampath Lokuge 19-Apr-14 4:39am    
What's the value you're trying to input for that text box ?
raxhemanth 19-Apr-14 4:58am    
10
raxhemanth 19-Apr-14 4:58am    
10,12,23 ...etc
Sampath Lokuge 19-Apr-14 5:28am    
Can you put the class 'clsbo' details ? code snippet of that class ?

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



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