Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table called Events where there are many columns and one of them is Time represented in 24/04/2015 12:00:00 AM format.
All I need is to fetch the time column and whenever the specified time arrives in system, a popup message should be displayed.
Here is My code (A method coded in the main form load)
I tried this but it doesnt popup a message, plz help.
C#
public void Reminders()
{
    SqlCeConnection conn = new SqlCeConnection("Data Source=E:\\Project Final_Year\\Project Final\\MyProject\\ERU Implementation\\VirtualPetedit\\VirtualPet\\MyDB.sdf");
    string query = "SELECT time FROM Events";
    SqlCeDataReader r;
    DateTime thisDay = DateTime.Today; 

    try
    {
        conn.Open();
        SqlCeCommand command = new SqlCeCommand(query, conn);
        r  = command.ExecuteReader();
        //if (r.HasRows)
        //{
            while (r.Read())
            {
                if (r.GetDateTime(0)  == thisDay )
                {
                    VirtualPet.Popup popup = new VirtualPet.Popup();
                    popup.Reminder();
                }
            }
        //}
       /* else
        {
            MessageBox.Show("No Reminder times currently");                          
        }*/
        conn.Close(); 
    }
    catch (Exception ex)
    { 
        MessageBox.Show(ex.Message.ToString());
    }
}
Posted
Updated 27-Apr-15 0:04am
v2
Comments
Sinisa Hajnal 27-Apr-15 6:05am    
Can you check what you get from r.GetDateTime(0)? Put that into message box...without if, so you always know what you get (or simply set a breakpoint and check)...esp. check that time component is the same
Abdul Rahman BCS 27-Apr-15 6:32am    
I dont get the popup as coded.. :(

Sinisa Hajnal 27-Apr-15 8:50am    
Yes, I realize that. I asked what you get if you call MsgBox(r.GetDateTime(0).ToString); - you should get a date from your database...or set a breakpoint and check the value.

Second thing to try is to call:
VirtualPet.Popup popup = new VirtualPet.Popup();
popup.Reminder();

Without condition, just to see that it appears as expected if the condition is satisfied.

1 solution

Hi The output of thisday format/datatype is not equle with what ever you have in your database, which means in database you have Date&Time with this format 4/04/2015 12:00:00 AM if you want to compare this format/datatype with current Date&Time (in this case thisday) you need to do like this:

C#
DateTime thisDay = DateTime.Today;
DateTime tag = r.GetDateTime(0);
int result = DateTime.Compare(thisDay, tag);
if (result < 0)
         relationship = "is earlier than";
      else if (result == 0)
         relationship = "is the same time as";         
      else
         relationship = "is later than";



Other related useful codes:
C#
DateTime myDateTime = DateTime.Now;
string sqlFormattedDate = myDateTime.ToString("yyyy-MM-dd HH:mm:ss");


Related Links:
http://www.java2s.com/Tutorial/CSharp/0560__ADO.Net/SqlDataReaderGetStringGetDateTime.htm[^]
https://msdn.microsoft.com/en-us/library/system.datetime.compare(v=vs.110).aspx[^]
http://www.dotnetperls.com/datetime-format[^]
https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx[^]
R,
Aydin
 
Share this answer
 
Comments
Abdul Rahman BCS 25-May-15 5:57am    
I am trying but no use, Can anyone help me solve this?
I have given a facility to user to select the reminder type (such as daily, weekly[user will be asked to select a day], on a special day)
and when the user add an event after filling such fields (event name, event description, reminder type, date and time) and the app should remind him the events on specific time.
Please help me to do with this task?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900