Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Date Range Function

Date Range Function

Scheduled Pinned Locked Moved C#
databasehelptutorial
5 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Reality Strikes
    wrote on last edited by
    #1

    To display report on Crystal Report I'm using, the following piece of code below.......but I'm not getting any idea of how to SELECT records between a date range ( in my database, the date field doesn't exist in date format, its splitted in multiple columns like MM, DD, YY, YY (i.e 4 columns altogether). when I display it on Crystal Report, I can concatenate it using built-in Crystal report fucntion called CStr function. If anyone has got any idea on how to proceed, pls help me.:confused:

    private void Form2_Load(object sender, System.EventArgs e)
    {
    try
    {
    myCon.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\sample_as400.mdb";
    myCon.Open();
    string sqlQuery = "Select * from table_as400";
    myAdp = new OleDbDataAdapter(sqlQuery, myCon);

       OleDbCommandBuilder myBldr = new OleDbCommandBuilder(myAdp);
       myAdp.Fill(myTable);					
      }
      catch (OleDbException exceptionObject)
      {
       MessageBox.Show(exceptionObject.Message, "PIN\_PROJECT");
      }
    

    }

    private void btnReport_Click(object sender, System.EventArgs e)
    {
    // Create a CrystalReport1 object
    CLIENT_REPORT myReport = new CLIENT_REPORT();

    // Set the DataSource of the report
    myReport.SetDataSource(myAdp);
    
    // Set the Report Source to ReportView 
    crystalReportViewer1.ReportSource = myReport;
    

    }

    P L 2 Replies Last reply
    0
    • R Reality Strikes

      To display report on Crystal Report I'm using, the following piece of code below.......but I'm not getting any idea of how to SELECT records between a date range ( in my database, the date field doesn't exist in date format, its splitted in multiple columns like MM, DD, YY, YY (i.e 4 columns altogether). when I display it on Crystal Report, I can concatenate it using built-in Crystal report fucntion called CStr function. If anyone has got any idea on how to proceed, pls help me.:confused:

      private void Form2_Load(object sender, System.EventArgs e)
      {
      try
      {
      myCon.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\sample_as400.mdb";
      myCon.Open();
      string sqlQuery = "Select * from table_as400";
      myAdp = new OleDbDataAdapter(sqlQuery, myCon);

         OleDbCommandBuilder myBldr = new OleDbCommandBuilder(myAdp);
         myAdp.Fill(myTable);					
        }
        catch (OleDbException exceptionObject)
        {
         MessageBox.Show(exceptionObject.Message, "PIN\_PROJECT");
        }
      

      }

      private void btnReport_Click(object sender, System.EventArgs e)
      {
      // Create a CrystalReport1 object
      CLIENT_REPORT myReport = new CLIENT_REPORT();

      // Set the DataSource of the report
      myReport.SetDataSource(myAdp);
      
      // Set the Report Source to ReportView 
      crystalReportViewer1.ReportSource = myReport;
      

      }

      P Offline
      P Offline
      paas
      wrote on last edited by
      #2

      One option would be to add a DateTime column to a dataset retrieved from your initial query of 'table_as400', loop through the dataset to edit/insert this DateTime column with the correct date according to the four various "date" related fields in each row of your table, and then pass that dataset object as your data source. You could then filter the date range according to the DateTime column you added. Of course, if your initial query is tens of thousands of records, this option is unlikely to be elegant. Another option would be to concatenate the date fields in your initial query AS some new named field into a "yyyyMMdd" format and then filter against that new field.

      R 1 Reply Last reply
      0
      • R Reality Strikes

        To display report on Crystal Report I'm using, the following piece of code below.......but I'm not getting any idea of how to SELECT records between a date range ( in my database, the date field doesn't exist in date format, its splitted in multiple columns like MM, DD, YY, YY (i.e 4 columns altogether). when I display it on Crystal Report, I can concatenate it using built-in Crystal report fucntion called CStr function. If anyone has got any idea on how to proceed, pls help me.:confused:

        private void Form2_Load(object sender, System.EventArgs e)
        {
        try
        {
        myCon.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\sample_as400.mdb";
        myCon.Open();
        string sqlQuery = "Select * from table_as400";
        myAdp = new OleDbDataAdapter(sqlQuery, myCon);

           OleDbCommandBuilder myBldr = new OleDbCommandBuilder(myAdp);
           myAdp.Fill(myTable);					
          }
          catch (OleDbException exceptionObject)
          {
           MessageBox.Show(exceptionObject.Message, "PIN\_PROJECT");
          }
        

        }

        private void btnReport_Click(object sender, System.EventArgs e)
        {
        // Create a CrystalReport1 object
        CLIENT_REPORT myReport = new CLIENT_REPORT();

        // Set the DataSource of the report
        myReport.SetDataSource(myAdp);
        
        // Set the Report Source to ReportView 
        crystalReportViewer1.ReportSource = myReport;
        

        }

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, if your database supports selection expressions you could do something like day+100*month+10000*year < 20080721 if it does not allow such, you will have to add a column containing day+100*month+10000*year or something similar, or just a real date! :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Voting for dummies? No thanks. X|


        R 1 Reply Last reply
        0
        • P paas

          One option would be to add a DateTime column to a dataset retrieved from your initial query of 'table_as400', loop through the dataset to edit/insert this DateTime column with the correct date according to the four various "date" related fields in each row of your table, and then pass that dataset object as your data source. You could then filter the date range according to the DateTime column you added. Of course, if your initial query is tens of thousands of records, this option is unlikely to be elegant. Another option would be to concatenate the date fields in your initial query AS some new named field into a "yyyyMMdd" format and then filter against that new field.

          R Offline
          R Offline
          Reality Strikes
          wrote on last edited by
          #4

          Thanks Paas, lemme try what you said.

          1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, if your database supports selection expressions you could do something like day+100*month+10000*year < 20080721 if it does not allow such, you will have to add a column containing day+100*month+10000*year or something similar, or just a real date! :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            Voting for dummies? No thanks. X|


            R Offline
            R Offline
            Reality Strikes
            wrote on last edited by
            #5

            I'm gonna play around with the expressions u mentioned, anyway THANKS a lot........!!!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups