Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am running into an exception during runtime that I have never seen before. I'm lost as to how to resolve it. Can someone shed some light as to what might be causing this?

Here is my code segment:
C#
SqlCeCommand code_comm_one = new SqlCeCommand("SELECT engine_code FROM vehicles WHERE make = @make AND model_name = @model AND model_year = @model_year AND engine_type = @engine_type", conn);
            SqlCeCommand code_comm_two = new SqlCeCommand("SELECT transmission_code FROM vehicles WHERE make = @make AND model_name = @model AND model_year = @model_year AND engine_type = @engine_type", conn);
            SqlCeCommand code_comm_three = new SqlCeCommand("SELECT abs_code FROM vehicles WHERE make = @make AND model_name = @model AND model_year = @model_year AND engine_type = @engine_type", conn);
            SqlCeCommand code_comm_four = new SqlCeCommand("SELECT comm_code FROM vehicles WHERE make = @make AND model_name = @model AND model_year = @model_year AND engine_type = @engine_type", conn);
            SqlCeCommand code_comm_five = new SqlCeCommand("SELECT accessory_code FROM vehicles WHERE make = @make AND model_name = @model AND model_year = @model_year AND engine_type = @engine_type", conn);
            
            // Executing Parameterized Queries
            code_comm_one.CommandType = CommandType.Text;
            code_comm_one.Parameters.AddWithValue("@make", makeComboBox.SelectedItem);
            code_comm_one.Parameters.AddWithValue("@model", modelComboBox.SelectedItem);
            code_comm_one.Parameters.AddWithValue("@model_year", yearComboBox.SelectedItem);
            code_comm_one.Parameters.AddWithValue("@engine_type", engineComboBox.SelectedItem);
            code_comm_one.ExecuteNonQuery();

            SqlCeDataReader code_dr_one = code_comm_one.ExecuteReader();
            SqlCeDataReader code_dr_two = code_comm_two.ExecuteReader();
            SqlCeDataReader code_dr_three = code_comm_three.ExecuteReader();
            SqlCeDataReader code_dr_four = code_comm_four.ExecuteReader();
            SqlCeDataReader code_dr_five = code_comm_five.ExecuteReader();

            if (code_dr_one.Read())
            {
                SqlCeCommand engine_path = new SqlCeCommand("SELECT accelerator_pedal_position FROM engine WHERE engine_code = @engine_code AND engine_type = '" + engineComboBox.Text + "'", conn);
                engine_path.CommandType = CommandType.Text;
                engine_path.Parameters.AddWithValue("@engine_code", code_dr_one.GetString(0));
                engine_path.ExecuteNonQuery();

                try
                {
                    SqlCeDataReader code_dr_one_prime = engine_path.ExecuteReader();
                    if(code_dr_one_prime.Read())
                    {
                        MessageBox.Show(code_dr_one_prime.GetString(0));
                    }
                }
                catch (SqlCeException ex)
                {
                    MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }         
                                
            code_comm_two.CommandType = CommandType.Text;
            code_comm_two.Parameters.AddWithValue("@make", makeComboBox.SelectedItem);
            code_comm_two.Parameters.AddWithValue("@model", modelComboBox.SelectedItem);
            code_comm_two.Parameters.AddWithValue("@model_year", yearComboBox.SelectedItem);
            code_comm_two.Parameters.AddWithValue("@engine_type", engineComboBox.SelectedItem);
            code_comm_two.ExecuteNonQuery();

            if (code_dr_two.Read())
            {
                SqlCeCommand transmission_path = new SqlCeCommand("SELECT turbine_speed_sensor FROM transmission WHERE trans_code = @trans_code AND trans_type = '" + transTypeComboBox.Text + "'", conn);
                transmission_path.CommandType = CommandType.Text;
                transmission_path.Parameters.AddWithValue("@trans_code", code_dr_two.GetString(0));
                transmission_path.ExecuteNonQuery();

                try
                {
                    SqlCeDataReader code_dr_two_prime = transmission_path.ExecuteReader();
                    if (code_dr_two_prime.Read())
                    {
                        MessageBox.Show(code_dr_two_prime.GetString(0));
                    }
                }
                catch (SqlCeException ex)
                {
                    MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }


Visual Studio is balking at the if statement (if(code_dr_two.Read()). Everything prior to that works seamlessly.

Thanks for your help.
Posted
Updated 1-Oct-12 12:22pm
v2
Comments
Sergey Alexandrovich Kryukov 1-Oct-12 18:21pm    
You are in much better position than I am. You "never seen before" this exception. As to me, I haven't seen it at all. You know why? Because you never reported it. I don't even have an idea what exception you are talking about :-) --SA
fjdiewornncalwe 1-Oct-12 19:12pm    
You need to give us the exception information as well so we know what we're looking at. We're not going to create an entire project and inject your code into it to get the exception message to help you.
joshrduncan2012 1-Oct-12 20:42pm    
Everyone, I apologize for not providing the exception that I was getting. It said "A Parameter is missing" "Parameter Ordinal=2". It had to do with an unhandled exception in the sqlcedatareader.dll file. I've googled for this for a while and have had no luck finding any sort of resolution to this.

1 solution

You haven't set any of the parameters you specified in the command string:
C#
SqlCeCommand code_comm_two = new SqlCeCommand("SELECT transmission_code FROM vehicles WHERE make = @make AND model_name = @model AND model_year = @model_year AND engine_type = @engine_type", conn);
You have set them for code_comm_one, but not for the others. Did you expect them to magically transfer?
 
Share this answer
 
Comments
Maciej Los 4-Oct-12 16:09pm    
+5!

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