Public void IntervalExample(TdCommand cmd, String client)
{
cmd.Parameters.Clear();
cmd.CommandText = "SELECT StartDate, AppointmentStart, DelayPeriod " +
"FROM Appointments " +
"WHERE Client = ?";
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(null, TdType.VarChar, 10,
ParameterDirection.Input, true, 0, 0, null,
DataRowVersion.Default, client);
Int32 row = 0;
TdDate [] startDate;
TdTimestamp [] appointmentStart;
TdIntervalHourToMinute [] appointmentLength;
using (TdDataReader dr = cmd.ExecuteReader())
{
startDate = new TdDate[dr.RecordsReturned];
appointmentStart = new TdTimestamp[dr.RecordsReturned];
appointmentLength = new TdIntervalHourToMinute [dr.RecordsReturned];
// Specifying an interval of 1 hour, 30 minutes with an hour precision of 2
TdIntervalHourToMinute AppointmentExtension = new TdIntervalHourToMinute(1, 30, 2);
while (dr.Read())
{
// Retrieving the dates
startDate[row] = dr.GetTdDate(0);
appointmentStart[row] = dr.GetTimestamp(1);
appointmentLength[row] = dr.GetTdIntervalHourToMinute(2);
// Adding extension to the lease return
appointmentStart[row] = appointmentStart[row] + AppointmentExtension;
// Adding extension to the lease length;
appointmentLength[row] = appointmentLength[row] + AppointmentExtension;
row++;
}
}
cmd.Parameters.Clear();
cmd.CommandText = "UPDATE Appointments " +
"SET AppointmentStart = ?, DelayPeriod = ? " +
"WHERE Client = ?";
cmd.Parameters.Add(null, TdType.Timestamp, 0,
ParameterDirection.Input, true, 0, 0, null,
DataRowVersion.Default, null);
cmd.Parameters.Add(null, TdType.IntervalHourToMinute, 0,
ParameterDirection.Input, true, 0, 0, null,
DataRowVersion.Default, null);
cmd.Parameters.Add(null, TdType.VarChar, 9,
ParameterDirection.Input, true, 0, 0, null,
DataRowVersion.Default, model);
row--;
while(row >= 0)
{
cmd.Parameters[0].Value = appointmentStart[row];
cmd.Parameters[1].Value = appointmentLength[row];
cmd.Parameters[2].Value = model;
cmd.ExecuteNonQuery();
row--;
}
}