CHAPTER 21 ADO.NET PART I: THE CONNECTED LAYER
{
}
Console.WriteLine(ex.Message);
}
Implementing the InsertNewCar() Method
Inserting a new record into the Inventory table is a simple matter of asking the user for the new bits of
data (using Console.ReadLine() calls) and passing this data into the InsertAuto() method of
InventoryDAL, like so:
private static void InsertNewCar(InventoryDAL invDAL)
{
// First get the user data.
int newCarID;
string newCarColor, newCarMake, newCarPetName;
Console.Write("Enter Car ID: ");
newCarID = int.Parse(Console.ReadLine());
Console.Write("Enter Car Color: ");
newCarColor = Console.ReadLine();
Console.Write("Enter Car Make: ");
newCarMake = Console.ReadLine();
Console.Write("Enter Pet Name: ");
newCarPetName = Console.ReadLine();
}
// Now pass to data access library.
invDAL.InsertAuto(newCarID, newCarColor, newCarMake, newCarPetName);
Recall that you overloaded InsertAuto() to take a NewCar object, rather than a set of independent
arguments. Thus, you could have implemented InsertNewCar() like this:
private static void InsertNewCar(InventoryDAL invDAL)
{
// First get the user data.
...
}
// Now pass to data access library.
NewCar c = new NewCar { CarID = newCarID, Color = newCarColor,
Make = newCarMake, PetName = newCarPetName };
invDAL.InsertAuto(c);
Implementing the UpdateCarPetName() Method
The following implementation of UpdateCarPetName() looks similar:
851