Product Documentation

FairCom ADO.NET Driver

Previous Topic

Next Topic

Manage

Manage() provides data management functionality for your application and/or process.

Below is the code for Manage():

static void Manage()

{

Console.WriteLine("MANAGE");

// delete any existing records

Delete_Records();

// populate the table with data

Add_CustomerMaster_Records();

// display contents of table

Display_Records();

// update a record under locking control

Update_CustomerMaster_Record();

// display again after update and effects of lock

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_CustomerMaster_Records()

//

// This function adds records to table CustomerMaster from an

// array of strings

//

static void Add_CustomerMaster_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);

}

}

//

// Update_CustomerMaster_Records()

//

// Update one record under locking control to demonstrate the effects

// of locking

//

static void Update_CustomerMaster_Record()

{

Console.WriteLine("\tUpdate record...");

try

{

cmd.Transaction = conn.BeginTransaction();

cmd.CommandText = "UPDATE custmast SET cm_custname = 'KEYON DOOLING' where cm_custnumb = '1003'";

cmd.ExecuteNonQuery();

Console.WriteLine("\tPress <ENTER> key to unlock");

Console.ReadLine();

cmd.Transaction.Commit();

}

catch (CtreeSqlException e)

{

Handle_Exception(e);

cmd.Transaction.Rollback();

}

catch (Exception e)

{

Handle_Exception(e);

}

}

TOCIndex