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. Web Development
  3. ASP.NET
  4. DataTable Select Query

DataTable Select Query

Scheduled Pinned Locked Moved ASP.NET
databasehelp
5 Posts 4 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.
  • M Offline
    M Offline
    Mugdha_Aditya
    wrote on last edited by
    #1

    Hello, I want to find record from table where given date is matching with given date i did as follwes but it given me error as Error : Syntax error: Missing operand after 'Date' operator. Code : for (int CountHoliday = 0; CountHoliday < 3; CountHoliday++) { string sqlFilter = "Holiday Date = '#" + Convert.ToDateTime(Al[CountHoliday]).ToShortDateString() + "#'"; DataRow[] dtRow = dsHoliday.Tables[0].Select(sqlFilter); if (dtRow[0].ItemArray[4].ToString() != "") { iCounter++; } }

    M A K J 4 Replies Last reply
    0
    • M Mugdha_Aditya

      Hello, I want to find record from table where given date is matching with given date i did as follwes but it given me error as Error : Syntax error: Missing operand after 'Date' operator. Code : for (int CountHoliday = 0; CountHoliday < 3; CountHoliday++) { string sqlFilter = "Holiday Date = '#" + Convert.ToDateTime(Al[CountHoliday]).ToShortDateString() + "#'"; DataRow[] dtRow = dsHoliday.Tables[0].Select(sqlFilter); if (dtRow[0].ItemArray[4].ToString() != "") { iCounter++; } }

      M Offline
      M Offline
      Mugdha_Aditya
      wrote on last edited by
      #2

      Got Answer :) Here it is : string sqlFilter = "HolidayDate = '" + Convert.ToDateTime(Al[CountHoliday]).ToShortDateString() + "'";

      1 Reply Last reply
      0
      • M Mugdha_Aditya

        Hello, I want to find record from table where given date is matching with given date i did as follwes but it given me error as Error : Syntax error: Missing operand after 'Date' operator. Code : for (int CountHoliday = 0; CountHoliday < 3; CountHoliday++) { string sqlFilter = "Holiday Date = '#" + Convert.ToDateTime(Al[CountHoliday]).ToShortDateString() + "#'"; DataRow[] dtRow = dsHoliday.Tables[0].Select(sqlFilter); if (dtRow[0].ItemArray[4].ToString() != "") { iCounter++; } }

        A Offline
        A Offline
        Abhishek Sur
        wrote on last edited by
        #3

        I would rather have employed LINQ to DataSet to filter those... Using

        dt.AsEnumerable()

        :cool:

        Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


        My Latest Articles-->** Windows7 API Code Pack
        Simplify Code Using NDepend
        Basics of Bing Search API using .NET

        1 Reply Last reply
        0
        • M Mugdha_Aditya

          Hello, I want to find record from table where given date is matching with given date i did as follwes but it given me error as Error : Syntax error: Missing operand after 'Date' operator. Code : for (int CountHoliday = 0; CountHoliday < 3; CountHoliday++) { string sqlFilter = "Holiday Date = '#" + Convert.ToDateTime(Al[CountHoliday]).ToShortDateString() + "#'"; DataRow[] dtRow = dsHoliday.Tables[0].Select(sqlFilter); if (dtRow[0].ItemArray[4].ToString() != "") { iCounter++; } }

          K Offline
          K Offline
          Kaushal Arora
          wrote on last edited by
          #4

          Hi, I am doing this thing using the method: for (int CountHoliday = 0; CountHoliday < 3; CountHoliday++) { string sqlFilter = "Holiday Day = '" + Convert.ToDateTime(Al[CountHoliday]).Day + "' and Holiday Month='" + Convert.ToDateTime(Al[CountHoliday]).Month + "' and Holiday Year='" + Convert.ToDateTime(Al[CountHoliday]).Year + "'"; DataRow[] dtRow = dsHoliday.Tables[0].Select(sqlFilter); if (dtRow[0].ItemArray[4].ToString() != "") { iCounter++; } } You have to get the Day, Month and Year in the DataTable as columns and use the filter in that. If you will be using the full datetime value for comparison it would not help you as it throws the error in some cases. Also try to name the columns without space like "Holiday Day" or "Holiday Date" should be "HolidayDay" or "HolidayDate" or you can use Underscore in place of Space. Regards, Kaushal Arora

          1 Reply Last reply
          0
          • M Mugdha_Aditya

            Hello, I want to find record from table where given date is matching with given date i did as follwes but it given me error as Error : Syntax error: Missing operand after 'Date' operator. Code : for (int CountHoliday = 0; CountHoliday < 3; CountHoliday++) { string sqlFilter = "Holiday Date = '#" + Convert.ToDateTime(Al[CountHoliday]).ToShortDateString() + "#'"; DataRow[] dtRow = dsHoliday.Tables[0].Select(sqlFilter); if (dtRow[0].ItemArray[4].ToString() != "") { iCounter++; } }

            J Offline
            J Offline
            Jeneesh K Velayudhan
            wrote on last edited by
            #5

            Hi Mugdha_Aditya, DataRow[] dtRow = dsHoliday.Tables[0].Select("Holiday Date = '" + Convert.ToDateTime(Al[CountHoliday]).ToShortDateString() + "'");

            Thanks & Regards, Jeneesh k. v.

            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