DataTable Select Query
-
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++; } }
-
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++; } }
Got Answer :) Here it is : string sqlFilter = "HolidayDate = '" + Convert.ToDateTime(Al[CountHoliday]).ToShortDateString() + "'";
-
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++; } }
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 -
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++; } }
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 -
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++; } }
Hi Mugdha_Aditya, DataRow[] dtRow = dsHoliday.Tables[0].Select("Holiday Date = '" + Convert.ToDateTime(Al[CountHoliday]).ToShortDateString() + "'");
Thanks & Regards, Jeneesh k. v.