|
-
Oct 29th, 2010, 07:34 AM
#1
Thread Starter
PowerPoster
[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:
Select Case MyDGV.SelectedCells(8).Value.ToString() Case "Radjesh" With MyMonthCal .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), _ New System.DateTime(2010, 4, 7), New System.DateTime(2010, 4, 14), New System.DateTime(2010, 4, 21), New System.DateTime(2010, 4, 28), _ New System.DateTime(2010, 5, 12), New System.DateTime(2010, 5, 19), New System.DateTime(2010, 5, 26)} MyNotes.Text = "blablablabla" .UpdateMarkedDates() Case "VB.NET" 'etc...
Let me start by asking what the best way would be to setup the table?
Thanks for the help in advance.
-
Oct 29th, 2010, 08:29 AM
#2
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 
-
Oct 29th, 2010, 08:43 AM
#3
Thread Starter
PowerPoster
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.
-
Oct 29th, 2010, 08:56 AM
#4
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 
-
Oct 29th, 2010, 09:07 AM
#5
Thread Starter
PowerPoster
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.
-
Oct 29th, 2010, 09:24 AM
#6
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 
-
Oct 29th, 2010, 09:36 AM
#7
Thread Starter
PowerPoster
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.
-
Oct 29th, 2010, 09:41 AM
#8
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 
-
Nov 11th, 2010, 07:15 AM
#9
Thread Starter
PowerPoster
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:
Dim mysqlstrConn As String = "server=myserver; Uid=table; database=table; pwd=password; connect timeout=30;" Dim mysqlConn As New MySql.Data.MySqlClient.MySqlConnection mysqlConn.ConnectionString = mysqlstrConn Dim StrCommDate As String = "SELECT datum_zitting FROM " & myDatagridview.SelectedCells(8).Value.ToString() Dim StrCommNotes As String = "SELECT extra_notes FROM " & myDatagridview.SelectedCells(8).Value.ToString() mysqlConn.Open() Dim mysqlCommDate As New MySqlCommand(StrCommDate, mysqlConn) Dim mysqlCommNotes As New MySqlCommand(StrCommNotes, mysqlConn) Dim mysqlAdapter As MySqlDataAdapter = New MySqlDataAdapter Dim mysqlTable As DataTable = New DataTable '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.
-
Nov 12th, 2010, 01:17 AM
#10
Thread Starter
PowerPoster
Re: Read date from database to monthcalendar
-
Nov 12th, 2010, 01:28 AM
#11
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.
-
Nov 12th, 2010, 01:42 AM
#12
Thread Starter
PowerPoster
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?
-
Nov 12th, 2010, 02:46 AM
#13
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 
-
Nov 12th, 2010, 03:17 AM
#14
Thread Starter
PowerPoster
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.
-
Nov 12th, 2010, 04:28 AM
#15
Re: Read date from database to monthcalendar
 Originally Posted by Radjesh Klauke
the issue remains that I still don't know how to pull the dates into the monthcalendar.
Um, like this maybe.
 Originally Posted by jmcilhinney
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.
-
Nov 16th, 2010, 07:28 AM
#16
Thread Starter
PowerPoster
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...
-
Nov 16th, 2010, 06:08 PM
#17
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|