Click here to Skip to main content
13,088,846 members (62,759 online)

How To exceute following code at specific day and specific time

Atul Rokade asked:

Open original thread
Hello friends,

I am create one application that application one file send to user at specific time and specific day export sql data into excle ,sending email that functions working fine but problems is that it cannot execute particular time and particular day I am paste here my code please help me out
if ((DateTime.Now.DayOfWeek== DayOfWeek.Saturday) &&(DateTime.Now.Hour==19) &&(DateTime.Now.Minute==15))
        public void exportsqldatatoexcle()
            string con1 = "Data Source=ADMIN\\SQLEXPRESS;Initial Catalog=PhysioCure; Integrated Security=true";
            SqlConnection connection = new SqlConnection(con1);
            sda = new SqlDataAdapter("select PationName,RegistrationDate,ContactNo,Age,Sex,Chief_Complain,Investigation_Result,PastHistoryAny,Physical_Examination,Medications,Prognosis,Electro_Therapy,Neuro_Rehabilitation,Ortho_Rehabilitation,Cardio_Pulmonery_Rehabilitation,Sports_Rehabilitation from Physio_cureTable order by RegistrationDate desc", con1);
            dt = new DataTable();
            DataColumnCollection dccollection = dt.Columns;
            Microsoft.Office.Interop.Excel.ApplicationClass excelapp = new Microsoft.Office.Interop.Excel.ApplicationClass();

            for (int i = 1; i < dt.Rows.Count + 1; i++)
                for (int j = 1; j < dt.Columns.Count + 1; j++)
                    if (i == 1)
                        excelapp.Cells[i, j] = dccollection[j - 1].ToString();
                        excelapp.Cells[i, j] = dt.Rows[i - 1][j - 1].ToString();
            excelapp.ActiveWorkbook.SaveCopyAs("E:\\Winform n console\\PhysioCure\\PhysioCure\\PhysioCure\\Patient_Details.xls");
            excelapp.ActiveWorkbook.Saved = true;
            MessageBox.Show("Detail file successfully create!");
        private void emailattachment()
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("");
                mail.From = new MailAddress("My email id");
                mail.To.Add("My frnd email id");
                mail.Subject = "Sending you Patient_Details File - 1";
                mail.Body = "Please Check Mail With Attachment";
                System.Net.Mail.Attachment attachment;
                attachment = new Attachment("E:\\Winform n console\\PhysioCure\\PhysioCure\\PhysioCure\\Patient_Details.xls");
                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("My email id", "Password");
                SmtpServer.EnableSsl = true;
                MessageBox.Show("Details File send on your mail please check your mail");

[Edit]Code block added[/Edit]
Tags: SQL-Server (SQL-server-2005), ADO.NET


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100