Public void DateExample(TdCommand cmd, String classId)
{
cmd.Parameter.Clear();
cmd.CommandText = "SELECT StartDate, EndDate " +
"FROM ClassEnrollment " +
"WHERE ClassId = ?";
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, classId);
TdDataReader dr = null;
Int32 i = 0;
Try
{
dr = cmd.ExecuteReader();
If (false == dr.Read())
{
return;
}
TdDate [] startDate = new TdDate[dr.RecordsReturned];
TdDate [] endDate = new TdDate[dr.RecordsReturned];
// An additional 5 days will be added to the start and end dates.
// The updates will be done the hard way. All the records will
// be read, 5 days will be added to the dates, and then each
// record will be updated.
// Specifying a TimeSpan of 5 days
System.TimeSpan fiveExtraDays = new TimeSpan(5, 0, 0, 0);
while (false == dr.Read())
{
// Retrieving the dates
startDate[i] = dr.GetTdDate(0);
endDate[i] = dr.GetTdDate(1);
// Going to add 5 days to the StartDate
startDate[i] = startDate[i] + fiveExtraDays
// Going to add 5 days to the EndDate
endDate[i] = endDate[i] + fiveExtraDays;
i++;
}
}
finally
{
if (dr != null)
{
dr.Close();
}
}
cmd.Parameters.Clear();
cmd.CommandText = "UPDATE classEnrollment " +
"SET StartDate = ?, EndDate = ? " +
"WHERE ClassId = ?";
cmd.Parameters.Add(null, TdType.Date, 0,
System.Data.ParameterDirection.Input, true, 0, 0, null,
System.Data.DataRowVersion.Default, null);
cmd.Parameters.Add(null, TdType.Date, 0,
System.Data.ParameterDirection.Input, true, 0, 0, null,
System.Data.DataRowVersion.Default, null);
cmd.Parameters.Add(null, TdType.Varchar, 9,
System.Data.ParameterDirection.Input, true, 0, 0, null,
System.Data.DataRowVersion.Default, classId);
i--;
while(i >= 0)
{
cmd.Parameters[0].Value = startDate[i];
cmd.Parameters[1].Value = endDate[i];
cmd.ExecuteNonQuery();
i--;
}
}