Public void PeriodDateExample(TdCommand cmd, String studentId)
{
cmd.Parameter.Clear();
cmd.CommandText = "SELECT timePeriod " +
"FROM ClassDetention " +
"WHERE StudentId = ?";
cmd.CommandType = CommandType.Text;
// creating the parameter
cmd.Parameters.Add(null, TdType.Varchar, 9,
System.Data.ParameterDirection.Input, true, 0, 0, null,
System.Data.DataRowVersion.Default, studentId);
TdDataReader dr = null;
Int32 i = 0;
TdPeriodTimestampWithTimeZone detention;
Try
{
dr = cmd.ExecuteReader();
If (false == dr.Read())
{
return;
}
// Retrieving the Period
detention = dr.GetTdPeriodTimestampWithTimeZone(0);
}
finally
{
if (dr != null)
{
dr.Close();
}
}
// An additional 1 day, 4 hours will be added to ending bound.
// Specifying a TimeSpan of 1 hour
System.TimeSpan extraDentention = new TimeSpan(1, 4, 0, 0);
// Getting the ending bound of the period and
// adding 1 hour to it
detention = new TdPeriodTime(detention.Begin, detention.End + extraDetention);
cmd.Parameters.Clear();
cmd.CommandText = "UPDATE classDetention " +
"SET timePeriod = ? " +
"WHERE StudentId = ?";
cmd.Parameters.Add(null, TdType.PeriodTimestampWithTimeZone, 0,
System.Data.ParameterDirection.Input, true, 0, 0, null,
System.Data.DataRowVersion.Default, detention);
cmd.Parameters.Add(null, TdType.Varchar, 9,
System.Data.ParameterDirection.Input, true, 0, 0, null,
System.Data.DataRowVersion.Default, studentId);
cmd.ExecuteNonQuery();
}