private void RegisterVehicle() { //here again we initiate the automart entities object AutomartEntities ae = new AutomartEntities(); try { int vID = 0; //We call the AddNewVehicle procedure and pass its parameters //from the text boxes. They really should be validated //first ae.usp_AddNewVehicle(txtLastName.Text, txtFirstName.Text, txtLicense.Text, txtMake.Text, txtYear.Text); var lic = ae.usp_GetVehicleandCustomerInfo(txtLicense.Text); foreach (var l in lic) { vID = l.VehicleID; //Write the vehicleID to a session variable Session["VehicleID"] = vID; } lblResult.Text = "Saved"; } catch (Exception ex) { lblResult.Text = ex.Message; } }
private void GetVehicle() { //call the stored procedure through the entities object //pass it the required parameters //store the stored proc results in a variable var veh = autoEntities.usp_GetVehicleandCustomerInfo(txtLicense.Text); //we will need the Vehicle ID //this variable is to store it int ID = 0; //we bind the query to the query list DataList1.DataSource = veh.ToList(); DataList1.DataBind(); //I call the stored proc again to get the vehicleID //you can only iterate through a result set once per var var vehID = autoEntities.usp_GetVehicleandCustomerInfo(txtLicense.Text); foreach (var v in vehID) { ID = v.VehicleID; //having got the vehicleID I store it //in a session variable //so it can be accessed from any page Session["VehicleID"] = ID; } //if there is no VehicleID then the employee //is directed to register the vehicle if (ID == 0) { lblResult.Text = "Vehicle Not found Please Register."; return; } //if all is well call the GetVehicleServices method GetVehicleServices(ID); }