Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-CE SQL Exception DataReader , +
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:
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 1-Oct-12 11:40am
Edited 1-Oct-12 13:22pm
v2
Comments
Sergey Alexandrovich Kryukov at 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
Marcus Kramer at 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 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You haven't set any of the parameters you specified in the command string:
            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?
  Permalink  
Comments
Maciej Los at 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)

  Print Answers RSS
0 OriginalGriff 505
1 Maciej Los 309
2 BillWoodruff 174
3 /\jmot 160
4 Suraj Sahoo | Coding Passion 160
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 2 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100