i'm trying to do some appointment book
so i decided to use MonthCalendar control and date changed event for choose the date

i tried dataset.table.rows.find() function on other tables which have int primary key and it works
its finds my row/s i need

but when i tried this func. on date type primary key it cannot find
i tried to
search with date type ==> fail
search with string type like 03.07.2012 ==> failed etc.

does anyone know what should i do?

thx for helps.

Recommended Answers

All 3 Replies

Check the format of the date information coming out of the database. It can appear as YYYY:MM:DD (particulary if you used an SQLfunction to enter the date in the first place) so searching for 03.07.2012 won't find anything. That tripped me up once.

What type of database are you using? You indicate the SQL Date type; to me this implies possibly a MySQL DB. If it is a MS SQL Server DB, the type is probably a datetime type. If this is the case then your data may contain a time component that is causing your search to fail.

Another possibility is how you are defining the search key value. If you use the MonthCalendar.SelectionStart property, there should not be a problem. If you are entering the date as string, you could be encountering a culture format issue.

Based on your "3.7.2012" format, I assume that you mean "3 July 2012". Assuming your data has a record for "3 July 2012", this code should work if: System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern ="dd.MM.yyyy"

      Dim d As Date = CDate("3.7.2012")
      Dim r As DataRow = dt.Rows.Find(d)

However this code will search for "7 March 2012" as it uses the invariant culture to covert the string to a date.

      Dim r As DataRow = dt.Rows.Find("3/7/2012")

I knew this was the case when using an expression filter (DataTable.Select(filter)) as it is stated in the documentation that this is so, but their is no corresponding comment for the DataRow.Find method (thankyou very much MS). I had to discover this the hard way.

ahh -.- it was my fault sorry i declare my dataset on form2 couse i always use my database on form2 but when i need diffrent table (which is i need to use on form1) i just create it and drag on same dataset so when i try to find row it cant find couse i didnt open form2-.- now i realize thats all :) by the way thx for your helps too ^^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.