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
  1. Home
  2. General Programming
  3. C#
  4. How to use "SELECT" statement on DataTables [modified]

How to use "SELECT" statement on DataTables [modified]

Scheduled Pinned Locked Moved C#
tutorial
4 Posts 2 Posters 0 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.
  • V Offline
    V Offline
    Verghese
    wrote on last edited by
    #1

    I want to use the "SELECT " statement on DataTable, which fetches records between these 2 date ranges: StartDate : 01-01-2007 and, EndDate : 01-01-2008 The code is as follows:

    if (newPDS.Tables[0].Columns["ADM_DATE"]== null)
    {
    DataColumn dCol = new DataColumn(newPDS.Tables[0].Columns.Add("ADM_DATE", typeof(DateTime), "").ToString());
    }

    for(Int32 i = 0; i < newPDS.Tables[0].Rows.Count; i++)
    {
    row = newPDS.Tables[0].Rows[i];
    row["ADM_DATE"] = row["CADMMM"] + "/" + row["CADMDD"] + "/" + row["CADMHH"] + row["CADMYY"];
    DateTime newDT = new DateTime();
    newDT = Convert.ToDateTime(row["ADM_DATE"]).Date;
    row["ADM_DATE"] = newDT.ToShortDateString();
    string newQuery = "ADM_DATE between StartDate and EndDate";
    newDR = myTable.Select(newQuery);
    }

    myReport.SetDataSource(newDR);
    crystalReportViewer1.ReportSource = myReport;

    Thanking you in anticipation.

    modified on Tuesday, August 5, 2008 3:33 PM

    W 1 Reply Last reply
    0
    • V Verghese

      I want to use the "SELECT " statement on DataTable, which fetches records between these 2 date ranges: StartDate : 01-01-2007 and, EndDate : 01-01-2008 The code is as follows:

      if (newPDS.Tables[0].Columns["ADM_DATE"]== null)
      {
      DataColumn dCol = new DataColumn(newPDS.Tables[0].Columns.Add("ADM_DATE", typeof(DateTime), "").ToString());
      }

      for(Int32 i = 0; i < newPDS.Tables[0].Rows.Count; i++)
      {
      row = newPDS.Tables[0].Rows[i];
      row["ADM_DATE"] = row["CADMMM"] + "/" + row["CADMDD"] + "/" + row["CADMHH"] + row["CADMYY"];
      DateTime newDT = new DateTime();
      newDT = Convert.ToDateTime(row["ADM_DATE"]).Date;
      row["ADM_DATE"] = newDT.ToShortDateString();
      string newQuery = "ADM_DATE between StartDate and EndDate";
      newDR = myTable.Select(newQuery);
      }

      myReport.SetDataSource(newDR);
      crystalReportViewer1.ReportSource = myReport;

      Thanking you in anticipation.

      modified on Tuesday, August 5, 2008 3:33 PM

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      Hi, Try using syntax #m/d/yy# for literal date strings. For example:

      string newQuery = "ADM_DATE between #1/1/2007# and #1/1/2008#";

      Mika

      V 1 Reply Last reply
      0
      • W Wendelius

        Hi, Try using syntax #m/d/yy# for literal date strings. For example:

        string newQuery = "ADM_DATE between #1/1/2007# and #1/1/2008#";

        Mika

        V Offline
        V Offline
        Verghese
        wrote on last edited by
        #3

        Thanks Mika. Just now I learned that, ADO.Net expressions do not support the "BETWEEN" keyword (it's showing an error as : Expression contains unsupported operator"BETWEEN").......so I just break it up into clauses with an "AND" as

        "ADM_DATE > StartDate AND ADM_DATE < EndDate"

        And when I'm using the above lines, its showing up the database connection popup, where it asks for Server Name, Database Type, LoginId, Password etc. That means that its still looking for the Crystal Reports datasource as DataSet's Table. My previously working Crystal Reports datasource expression was like this :

        myReport.SetDataSource(newPDS.Tables["SAMFILE_CLIENTP"]);

        where : newPDS - DataSet SAMFILE_CLIENTP - DataSet Table Any idea ???

        W 1 Reply Last reply
        0
        • V Verghese

          Thanks Mika. Just now I learned that, ADO.Net expressions do not support the "BETWEEN" keyword (it's showing an error as : Expression contains unsupported operator"BETWEEN").......so I just break it up into clauses with an "AND" as

          "ADM_DATE > StartDate AND ADM_DATE < EndDate"

          And when I'm using the above lines, its showing up the database connection popup, where it asks for Server Name, Database Type, LoginId, Password etc. That means that its still looking for the Crystal Reports datasource as DataSet's Table. My previously working Crystal Reports datasource expression was like this :

          myReport.SetDataSource(newPDS.Tables["SAMFILE_CLIENTP"]);

          where : newPDS - DataSet SAMFILE_CLIENTP - DataSet Table Any idea ???

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          Glad it solved. It's been a while since I last used Crystal but if I remember correctly, try also to use SetDatabaseLogon method and after setting databases and datasources, use VerifyDatabase-method. This way you have full control over datasources and their logon information and you can catch any possible problems while executing VerifyDatabase. Hope this helps, Mika

          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