Free mag vol1 | Page 906

CHAPTER 21  ADO.NET PART I: THE CONNECTED LAYER private static void UpdateCarPetName(InventoryDAL invDAL) { // First get the user data. int carID; string newCarPetName; Console.Write("Enter Car ID: "); carID = int.Parse(Console.ReadLine()); Console.Write("Enter New Pet Name: "); newCarPetName = Console.ReadLine(); // Now pass to data access library. invDAL.UpdateCarPetName(carID, newCarPetName); } Implementing LookUpPetName() Obtaining the pet name of a given automobile works similarly to the previous methods; this is so because the data access library encapsulates all of the lower-level ADO.NET calls. private static void LookUpPetName(InventoryDAL invDAL) { // Get ID of car to look up. Console.Write("Enter ID of Car to look up: "); int id = int.Parse(Console.ReadLine()); Console.WriteLine("Petname of {0} is {1}.", id, invDAL.LookUpPetName(id).TrimEnd()); } With this, your console-based front end is finished! It’s time to run your program and test each method. Here is some partial output that tests the L, P, and Q commands: ***** The AutoLot Console UI ***** I: U: D: L: S: P: Q: Inserts a new car. Updates an existing car. Deletes an existing car. Lists current inventory. Shows these instructions. Looks up pet name. Quits program. Please enter your command: L CarID Make Color PetName ---------------------------------83 Ford Rust Rusty 107 Ford Red Snake 678 Yugo Green Clunker 904 VW Black Hank 1000 BMW Black Bimmer 852