Public void TimeExample(TdCommand cmd, String classId)
{
cmd.Parameters.Clear();
cmd.CommandText = "SELECT StartTime, EndTime FROM ClassInfo " +
"WHERE ClassId = ?";
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(null, TdType.Varchar, 9,
System.Data.ParameterDirection.Input, true, 0, 0, null,
System.Data.DataRowVersion.Default, classid);
TdDataReader dr = null;
// This will be added to TdTime. The timespan has been set to 1 hour.
Timespan hourLater = new Timespan(1, 0, 0);
// Going to add an hour to the start and end times of the class.
// This is going to be done the hard way to demonstrate TdTime.
Try
{
dr = cmd.ExecuteReader();
// Only one record is returned from query
TdTimeWithTimeZone startTime = dr.GetTdTimeWitTimeZone(0);
TdTimeWithTimeZone endTime = dr.GetTdTimeWithTimeZone(1);
dr.Close();
startTime = startTime + hourLater;
endTime = endTime + hourLater;
// Going to update the class record to indicate that the
// class will start an hour later.
cmd.CommandText = "UPDATE ClassInfo " +
"SET StartTime = ?, EndTime = ? " +
"WHERE ClassId = ?";
cmd.Parameters.Clear();
cmd.Parameters.Add(null, TdType.TimeWithTimeZone, 0,
System.Data.ParameterDirection.Input, true, 0, 0, null,
System.Data.DataRowVersion.Default, startTime);
cmd.Parameters.Add(null, TdType.TimeWithTimeZone, 0,
System.Data.ParameterDirection.Input, true, 0, 0, null,
System.Data.DataRowVersion.Default, endTime);
cmd.Parameters.Add(null, TdType.Varchar, 9,
System.Data.ParameterDirection.Input, true, 0, 0, null,
System.Data.DataRowVersion.Default, classid);
cmd.ExecuteNonQuery();
}
finally
{
if (dr != null)
{
dr.Close();
}
}
}