Results 1 to 17 of 17

Thread: [RESOLVED] Read date from database to monthcalendar

  1. #1

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Resolved [RESOLVED] Read date from database to monthcalendar

    Ola,

    Now I've hardcoded my date into my app, but now I want to read it from the database. I knowhow to read the columns, but unfortunately I don't now how to make the date appear into the monthcalendar.

    vb.net Code:
    1. Select Case MyDGV.SelectedCells(8).Value.ToString()
    2.     Case "Radjesh"
    3.         With MyMonthCal
    4.             .MarkedDates = New System.DateTime() {New System.DateTime(2010, 3, 3), New System.DateTime(2010, 3, 10), New System.DateTime(2010, 3, 17), New System.DateTime(2010, 3, 24), New System.DateTime(2010, 3, 31), _
    5.             New System.DateTime(2010, 4, 7), New System.DateTime(2010, 4, 14), New System.DateTime(2010, 4, 21), New System.DateTime(2010, 4, 28), _
    6.             New System.DateTime(2010, 5, 12), New System.DateTime(2010, 5, 19), New System.DateTime(2010, 5, 26)}
    7. MyNotes.Text = "blablablabla"
    8.         .UpdateMarkedDates()
    9.     Case  "VB.NET"
    10.         'etc...

    Let me start by asking what the best way would be to setup the table?

    Thanks for the help in advance.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  2. #2
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Read date from database to monthcalendar

    how about reading the date columns into array or list of Datetime and use them inside the calendar constructor ?

    p.s i never used the calender control so pardon moi if i'm talking nonsense
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  3. #3

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Read date from database to monthcalendar

    how about reading the date columns into array or list of Datetime
    Yes, but how. First I need to know how to design the table.
    How should I set the date in the colum(s), how should I read it. First I need to know what would be the best way to setup the table(s).
    Last edited by Radjesh Klauke; Oct 29th, 2010 at 08:58 AM.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  4. #4
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Read date from database to monthcalendar

    if you don't know how many dates each row should hold it would be better to give the dates a table of its own with relationship key and each date will have it's own row:

    Code:
    record_id (int/PK)  |  date_value (DateTime)   |  relationship key (the id that connect between this table and the table of the record  the dates are belonging to)
    1                           1900-01-01 00:00                25
    Last edited by motil; Oct 29th, 2010 at 09:03 AM.
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  5. #5

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Read date from database to monthcalendar

    That's very interesting. Never used relationship-key's.
    So actually you are saying to create a table for each "ID", if I'm getting this correct.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  6. #6
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Read date from database to monthcalendar

    i don't think you get me correct, let's say you have a primary table the holds list of countries, each country has it's own holiday dates, so the the countries table will look something like that:
    Code:
    tbl_countries:
    ----------------------------
    country_id  |  country_name
     1                   Country 1
     2                   Country 2
     3                   Country 3
    -------------------------------
    now each country has different number of holidays so you use another table to hold all the countries holidays dates:
    Code:
    tbl_countries_dates:
    id   |  holiday_date   | country_id
    1       1900/01/01              1                 < --- this date record is holiday date of Country 1
    2       1900/05/01              1                 < --- this date is also holiday date of Country 1
    3       1900/05/25              3                 < --- this date is holiday date of Country 3
    4       1900/05/05              2                 < --- this date is holiday date of Country 2
    so Country 1 has two holidays dates and country 2 and 3 has one holiday date each.
    this way you can hold unlimited number of dates for each country.

    is it clear enough?
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  7. #7

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Read date from database to monthcalendar

    I think I get it. But how would my Query look like?

    EDIT: Wait... I think in this case it is better to create a (date)table for each office.
    Last edited by Radjesh Klauke; Oct 29th, 2010 at 09:40 AM.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  8. #8
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Read date from database to monthcalendar

    you can get the dates like so (using my example):

    A) if you wish to get dates by country id with full details
    Code:
    SELECT A.country_id,A.country_name,B.holiday_date 
    FROM tbl_countries A INNER JOIN tbl_countries_dates B
    WHERE A.country_id = 1"
    if you wish to get all dates of all countries just omit the where clause :
    Code:
    SELECT A.country_id,A.country_name,B.holiday_date 
    FROM tbl_countries A INNER JOIN tbl_countries_dates B
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  9. #9

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Read date from database to monthcalendar

    Okay,

    I created al the tables I needed. Each table has the same name as myDatagridview.SelectedCells(8).Value.Tostring.

    Here's how each table looks like:



    In the first column the dates are stored and in the second the notes.

    The dates needs to be added into the monthcalendar and the note(s) into a RTB. Here's the code I have so far:

    vb.net Code:
    1. Dim mysqlstrConn As String = "server=myserver; Uid=table; database=table; pwd=password; connect timeout=30;"
    2. Dim mysqlConn As New MySql.Data.MySqlClient.MySqlConnection
    3. mysqlConn.ConnectionString = mysqlstrConn
    4.  
    5. Dim StrCommDate As String = "SELECT datum_zitting FROM " & myDatagridview.SelectedCells(8).Value.ToString()
    6. Dim StrCommNotes As String = "SELECT extra_notes FROM " & myDatagridview.SelectedCells(8).Value.ToString()
    7.  
    8. mysqlConn.Open()
    9.  
    10. Dim mysqlCommDate As New MySqlCommand(StrCommDate, mysqlConn)
    11. Dim mysqlCommNotes As New MySqlCommand(StrCommNotes, mysqlConn)
    12.  
    13. Dim mysqlAdapter As MySqlDataAdapter = New MySqlDataAdapter
    14. Dim mysqlTable As DataTable = New DataTable
    15. 'Dim mysqlReader As MySqlDataReader
    Now I'm stuck. I know what to do, but how...

    Anyone? Thanks in advance.
    Last edited by Radjesh Klauke; Nov 12th, 2010 at 01:18 AM.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  10. #10

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Read date from database to monthcalendar

    Anyone?


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Read date from database to monthcalendar

    First up, you need to get your database design sorted. It's a very bad idea to have separate tables when the data is basically the same. You should absolutely not have a separate table for dates for each office. You should have a table for offices and a table for dates and each date record contains an office ID. You can then query the database for all dates with a specific office ID. You can read the results into a List(Of Date) using a DataReader and call ToArray or you can use populate a DataTable using a DataAdapter and use LINQ to get an array of Dates. Once you've got your array, you use just as you did in your original code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Read date from database to monthcalendar

    It seems that I first need to learn how to design proper databases. Any suggestions where to look?


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  13. #13
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Read date from database to monthcalendar

    this is exactly what i suggested and even give you example of how to do it... read closely.
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  14. #14

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Read date from database to monthcalendar

    I know m8. But then I also have to re-design my whole database.
    But the issue remains that I still don't know how to pull the dates into the monthcalendar.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  15. #15
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Read date from database to monthcalendar

    Quote Originally Posted by Radjesh Klauke View Post
    the issue remains that I still don't know how to pull the dates into the monthcalendar.
    Um, like this maybe.
    Quote Originally Posted by jmcilhinney View Post
    You can then query the database for all dates with a specific office ID. You can read the results into a List(Of Date) using a DataReader and call ToArray or you can use populate a DataTable using a DataAdapter and use LINQ to get an array of Dates. Once you've got your array, you use just as you did in your original code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  16. #16

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: [RESOLVED] Read date from database to monthcalendar

    Ai... accidentally set this one as resolved...

    You can read the results into a List(Of Date) using a DataReader and call ToArray or you can use populate a DataTable using a DataAdapter and use LINQ to get an array of Dates. Once you've got your array, you use just as you did in your original code.
    Uuuuuh.... very nice, but don't know how to code that. Also searched the web for examples how to load "date" from a server, but nothing...


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  17. #17
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] Read date from database to monthcalendar

    You're trying to complicate something that's very simple. Retrieving data from a database is the same regardless of the data type. If you know how to get any data from a database then you know how to get dates from a database. Just execute a query exactly as you usually would. The data you get back will be Dates if the data your retrieved is dates.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width