2 Replies - 1643 Views - Last Post: 04 June 2011 - 10:58 AM Rate Topic: -----

#1 garshiya  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-May 11

How to delete data from given date - current date using datetimepicker

Posted 02 June 2011 - 10:33 PM

Hi,
I am having a Problem ,
My Problem is to delete data from a file ,
My code deletes only the given date in dateTimePicker1.Text,
It only deletes one day data,
I want to delete the data from the date given in dateTimePicker1.Text to current date,
is there anyway to delete the data from given date to current date.
Is There Any Suggestions for my Question.
My CODE Is,

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string todaysDate;
            todaysDate = dateTimePicker1.Text;
            int FinalDate4 = 0;
            string Destinationnsefx = "C:\\folder\\subfolder";
            string SecSym = (9722).ToString();
            MLBWriterClass writerdelete1 = new MLBWriterClass();//this dll reads the data files 
            try
            {
                writerdelete1.OpenDirectory(Destinationnsefx);
                writerdelete1.OpenSecurityBySymbol(SecSym);
                FinalDate4 = int.Parse(todaysDate);
                if (writerdelete1.get_bDateExists(FinalDate4))
                {
                    try
                    {
                        writerdelete1.DeleteIntradaySecRecordEx(FinalDate4, 080000, 240000);
                    }
                    catch (Exception)
                    {

                    }
                }
                writerdelete1.CloseSecurity();
                writerdelete1.CloseDirectory();

            }
            catch (Exception)
            {

            }

        }
    }
}

Can Anyone Please Help Me,

MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 03 June 2011 - 02:34 AM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: How to delete data from given date - current date using datetimepicker

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,515
  • Joined: 23-August 08

Re: How to delete data from given date - current date using datetimepicker

Posted 03 June 2011 - 02:35 AM

garshiya, when you post code obey the rules -- which are displayed EVERYWHERE on the site -- and USE CODE TAGS!!!

:code:

If that's too complicated, then see the first link in my signature.
Was This Post Helpful? 0
  • +
  • -

#3 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: How to delete data from given date - current date using datetimepicker

Posted 04 June 2011 - 10:58 AM

Hey garshiya, welcome to the forums :)

What is 'SecSym' all about? It looks interesting. Does MLB have anything to do with major league baseball? Also, try iterating over a for loop for every day between X and now:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            // We must setup two DateTime objects...  I arbitrarily decided I wanted them both in the same array
            DateTime[] dateRange = new DateTime[2];
            dateRange[0] = new DateTime(2011,1,1);
            dateRange[1] = new DateTime(2011,1,20);


            // this GetDateRange function will return a list of each day between the two dates passed in as parameters
            // eg.   2011,1,1   
            //       2011,1,2
            //       2011,1,3
            //       ...
            //       2011,1,20
            List<DateTime> reportRange = GetDateRange(dateRange[0], dateRange[1]);

            //Swell!  They're even in date time format!

            foreach (DateTime date in reportRange)
            {
                MessageBox.Show("Rplace with payload.  Proof: " + date.ToShortDateString());
            }

        }



        /// <summary>
        /// Returns a list of dates beginning with StartingDate and ending with EndingDate
        /// Returns null if you got the order backwords (doh!)  =)
        /// </summary>
        /// <param name="StartingDate"></param>
        /// <param name="EndingDate"></param>
        /// <returns></returns>
        private List<DateTime> GetDateRange(DateTime StartingDate, DateTime EndingDate)
        {
            if (StartingDate > EndingDate)
                return null;   // negitave numbers do not exist!  =P

            List<DateTime> dates = new List<DateTime>();
            DateTime tmpDate = StartingDate;

            do // atleast once
            {
                dates.Add(tmpDate);  // add each date to our list
                tmpDate = tmpDate.AddDays(1); // i++
            } while (tmpDate <= EndingDate);    // and until EndingDate of course

            return dates;
        }
    }
}



I could never decide if that was an efficient algo or not, because I couldn't think of any alternatives.

PS. We do love our tags here =)

This post has been edited by NotarySojac: 04 June 2011 - 10:58 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1