So here is my dilema... Form1 user sorts through textboxes and combos ending up selecting a car of choice,,,,
car of choice is then display in a Form2 with info and a picture in the picture box. User then has an option to
change the colour of the car with a combo box (database loaded with available colours) Below is my code and the error message.
I don't know what I'm doing wrong (obviously). Please help. Thanks so much
using System.Data.SqlClient; using System.IO; using System.Reflection; namespace Project_1___CarPurchase { public partial class Form_2_YourVehicleSelection : Form { SqlConnection conn = new SqlConnection("Data Source=localhost;Initial catalog=dbSD16Project1CarPurchase; Integrated Security = SSPI"); bool firsttime = true; public Form_2_YourVehicleSelection() { InitializeComponent(); loadLabels(Globals.VehicleID); loadComboBox(Globals.VehicleID); } private void loadLabels(int VehicleID) { SqlDataAdapter daVehicle = new SqlDataAdapter("spGetVehicles", conn); daVehicle.SelectCommand.CommandType = CommandType.StoredProcedure; DataSet dsVehicle = new DataSet(); daVehicle.SelectCommand.Parameters.Add("@VehicleID", VehicleID); daVehicle.SelectCommand.Parameters.Add("@Colour", Globals.colColour); daVehicle.Fill(dsVehicle); lblID.Text = dsVehicle.Tables[0].Rows[0]["VehicleID"].ToString();
IndexOutOfRangeException was unhandled = There is no row at position 0 lblType.Text = dsVehicle.Tables[0].Rows[0]["vehtype"].ToString(); lblYear.Text = dsVehicle.Tables[0].Rows[0]["vehYear"].ToString(); lblMake.Text = dsVehicle.Tables[0].Rows[0]["vehMake"].ToString(); lblModel.Text = dsVehicle.Tables[0].Rows[0]["vehModel"].ToString(); lblPrice.Text = dsVehicle.Tables[0].Rows[0]["vehPrice"].ToString(); string sfullpath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"..\..\..\Photos\"+ dsVehicle.Tables[0].Rows[0]["colPhotoPath"].ToString(); pboxVehicleSelection.ImageLocation = sfullpath; } private void loadComboBox(int VehicleID) { SqlDataAdapter daVehicle = new SqlDataAdapter("spColourLoad", conn); daVehicle.SelectCommand.CommandType = CommandType.StoredProcedure; DataSet dsVehicle = new DataSet(); daVehicle.SelectCommand.Parameters.Add("@VehicleID", VehicleID); daVehicle.Fill(dsVehicle); cmboxAnotherColour.DataSource = dsVehicle.Tables[0]; cmboxAnotherColour.DisplayMember = "colColour"; cmboxAnotherColour.ValueMember = "ColourID"; cmboxAnotherColour.SelectedIndex = -1; firsttime = false; } private void cmboxAnotherColour_SelectedIndexChanged(object sender, EventArgs e) { if (!firsttime) { Globals.colColour = cmboxAnotherColour.SelectedText.ToString(); loadLabels(Globals.VehicleID); }
'Stop my insanity'