Manage() provides data management functionality for your application and/or process.
Below is the code for Manage():
//
// Manage()
//
// This function performs simple record functions of add, delete and gets
//
static void Manage()
{
Console.WriteLine("MANAGE");
// delete any existing records
Delete_Records();
// populate the table with data
Add_Records();
// display contents of table
Display_Records();
}
//
// Delete_Records()
//
// This function deletes all the records in the table
//
static void Delete_Records()
{
Console.WriteLine("\tDelete records...");
try
{
cmd.CommandText = "DELETE FROM custmast";
cmd.ExecuteNonQuery();
}
catch (CtreeSqlException e)
{
Handle_Exception(e);
}
catch (Exception e)
{
Handle_Exception(e);
}
}
//
// Add_Records()
//
// This function adds records to a table in the database from an
// array of strings
//
static void Add_Records()
{
String[] data = {
"('1000','92867','CA','1','Bryan Williams','2999 Regency','Orange')",
"('1001','61434','CT','1','Michael Jordan','13 Main','Harford')",
"('1002','73677','GA','1','Joshua Brown','4356 Cambridge','Atlanta')",
"('1003','10034','MO','1','Keyon Dooling','19771 Park Avenue','Columbia')"
};
Console.WriteLine("\tAdd records...");
try
{
// add one record at time to table
for (int i = 0; i < data.Length; i++)
{
cmd.CommandText = "INSERT INTO custmast VALUES " + data[i];
cmd.ExecuteNonQuery();
}
}
catch (CtreeSqlException e)
{
Handle_Exception(e);
}
catch (Exception e)
{
Handle_Exception(e);
}
}
//
// Display_Records()
//
// This function displays the contents of a table.
//
static void Display_Records()
{
Console.Write("\tDisplay records...");
try
{
cmd.CommandText = "SELECT * FROM custmast";
// get a resultset
rdr = (CtreeSqlDataReader)cmd.ExecuteReader();
// read the returned resultset
while (rdr.Read())
{
Console.WriteLine("\n\t\t{0} {1}", rdr.GetString(0), rdr.GetString(4));
}
// close the reader
rdr.Close();
}
catch (CtreeSqlException e)
{
Handle_Exception(e);
}
catch (Exception e)
{
Handle_Exception(e);
}
}