Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi Guys,Im trying to filter acording to the selected velue from the combobox, now i get this error every time I run my application "Input string was not in a correct format."

Below is my Client form

C#
public partial class Form1 : Form
     {

        public ProductsBL productBL;
        public ArrayList prodList;
        ArrayList list;
        public Form1()
        {
            InitializeComponent();
             productBL = new ProductsBL();
             prodList = new ArrayList();
             prodList = productBL.getProducts();
             
             dataGridView1.DataSource = prodList;
             dataGridView1.Columns[0].Visible = false;
             prodList = productBL.loadComboboxProductID();
             comboBox1.DataSource = prodList;
             //prodList = new ArrayList();
            
        }
    }
   private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Products products = productBL.getSpecificProducts(Convert.ToInt32 
            (comboBox1.SelectedValue));
            dataGridView1.DataSource = products;

        }

Below is my Business Layer


 public Products getSpecificProducts(int productID)
        {
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("procGetSingleRowOnProducts", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@productID", SqlDbType.Int));
                cmd.Parameters["@productID"].Value = productID;
                
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                reader.Read();
                               
                    Products products = new Products(Convert.ToInt32(reader["ProductID"]), Convert.ToString(reader["productName"]), Convert.ToInt32(reader["supplierID"]), Convert.ToInt32(reader["categoryID"]), Convert.ToString(reader["quantityPerUnit"]), Convert.ToDouble(reader["unitPrice"]), Convert.ToInt16(reader["UnitsInStock"]), Convert.ToInt16(reader["UnitsOnOrder"]), Convert.ToInt16(reader["ReorderLevel"]), Convert.ToBoolean(reader["Discontinued"]));
                    
                               return products;
            }//End 
        }
Posted
Updated 9-Mar-11 20:29pm
v3
Comments
Olivier Levrey 10-Mar-11 4:39am    
Why don't you use the debugger to know where the exception comes from?? Identifying the source of the problem is the first step of solving it. After seeing the line which throws the exception you can in 90% of the cases solve it in less than 10 seconds.
Anele Ngqandu 10-Mar-11 8:38am    
Yes I did try that but still I just dont understand the problem. Below is the line
Products products = productBL.getSpecificProducts(Convert.ToInt32 (comboBox1.SelectedValue));

1 solution

You must use

Products products = productBL.getSpecificProducts(Convert.ToInt32(comboBox1.SelectedItem));
 
Share this answer
 
Comments
Anele Ngqandu 10-Mar-11 8:38am    
I did but now its not loading acording to selected
Ryan Zahra 10-Mar-11 8:43am    
Debug your code! Check the values that are passed to the business logic and the values that are loaded from the database.

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