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);
TdPeriodDate detention;
using (TdDataReader dr = cmd.ExecuteReader())
{
If (false == dr.Read())
{
return;
}
// Retrieving the Period
detention = dr.GetTdPeriodDate(0);
}
// An additional 5 days will be added to ending bound.
// Specifying a TimeSpan of 5 days
System.TimeSpan fiveExtraDays = new TimeSpan(5, 0, 0, 0);
// Getting the ending bound of the period and
// adding 5 days to it
TdDate endOfDetention = detention.End + fiveExtraDays;
detention = new TdPeriodDate(detention.Begin, endOfDetention);
cmd.Parameters.Clear();
cmd.CommandText = "UPDATE classDetention " +
"SET timePeriod = ? " +
"WHERE StudentId = ?";
cmd.Parameters.Add(null, TdType.PeriodDate, 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();
}