-2
私は以下のコードに残った日数を表示しようとしています。データベース..のような日常の残り日数べき、あなたが何かを得れば、あなたがデータベースから得るものがあり、あなたの文字列の形式と間違って何かが「最初」であり、「第二」のデバッグ私はメッセージボックスに以下のコードを表示します。エラーはありません。ただし、メッセージボックスを表示していません。
//i want to get the two dates which is already saved in sql and then
//calculating the remaining days
//reading the data
using (SqlDataReader read = cmd.ExecuteReader()) {
//loop throught the reader
while (read.Read()) {
// putting the salarydate value from database to first variable
String first =(read["salarydate"].ToString());
// putting the expirydate value from database to second variable
String Second = (read["expiredate"].ToString());
//converting the first fron string to datetime and then saving it to another
//datetime variable name salaryDate
DateTime salaryDate = DateTime.ParseExact(first, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
//converting the second fron string to datetime and then saving it to another
//datetime variable name expireDate
DateTime expireDate = DateTime.ParseExact(Second, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
//timepaning between two
TimeSpan t1 = expireDate - salaryDate;
//storing the days from t1 to daysleft which means days remaining
int daysleft = t1.Days; //days left
//this message box is not showing
//i also want to save the difference in sql and when that difference become
//zero , i want to put condition on that ..
MessageBox.Show(daysleft.ToString(),"Days Left");
}
}
コードにはどのような問題がありますか? – FeliceM
ここにあります: エラー: 文字列が有効ではありませんDateTime。 –
文字列はどのように見えますか?それをデバッグします。 – LarsTech