creating an array, checking for keys w/in, and looping through

liunx

Guest
I am a newbie to .NET programming, and I'm trying to develop a basic calendar system. I have programmed something similar to this in PHP and MySQL, but there are a few things I'm stuck on in developing this through Visual Studio .NET.

1) I would like to pull all the events for a given month from SQL and form an array. If I were coding in PHP, I would code this as:

while($array = mysql_fetch_array($result)) {
$event_array[$array["day"]] = "event";
}

This would create a very simple array of all the days (in the key) that are returned from the given query, where my SQL query would pull all the events for a given month and year. So how would I code that query and create the array in the .NET framework?

2) Once I have such an array, how could I see if a key value exists? When I'm building the calendar, I want to put a hyperlink behind the number if it's in that array created in part 1. Again, if I were coding this in PHP it would be something like this:

// the day variable is being defined as I build the calendar
if(array_key_exists($day, $event_array)) {
echo "<td><a href='http://www.webdeveloper.com/forum/archive/index.php/?iDay=".$day."'>".$day."</a></td>";
} else {
echo "<td>".$day."</td>";
}


3) Lastly, once the user selects a day, how could I list all the events on the screen for the selected day? If I were doing this in PHP and MySQL, it would do something like this:

while($event = mysql_fetch_array($event_result)) {
echo "<h3>".$event["event_title"]."</h3>\n";
echo $event["stating_time_hour"]." ".$event["stating_time_minutes"]." ".$event["stating_time_am_pm"];
}


I've got the rest of it working more or less, but these three things have me at a loss at the moment.


Thanks,

ShaunLook into the System.Collections namespace, in particular the Hashtable collection. A Hashtable stores key/value pairs and can be searched by key. When you want to enumerate the collection, create an enumerator using the GetEnumerator method and then do a simple for->each loop. Hope that helps.
 
Back
Top