Saturday, February 25, 2012

Can someone see whats wrong...??

I have a SQL query in my asp.net & c# application. im trying to retrieve the data from two tables where the ID's of the tables match. once this is found i am obtaining the value associated with one of the keys. e.g. my two tables

Event EventCategoryType

Field Type Example Field Type Example
EventID Int(4) 1 CategoryID(PK)int(4) 1
CategoryID(FK)int(4) 1 Type varchar(50) Exercise
Type varchar (200) Exercise Color varchar(50) Brown

The CategoryID is a 1:n relationship. my SQL query will retrive the values where the CategoryIDs match and the Tyoe matches as well. once this is found it will apply the associated color with that categoryID (each unique category has its own Color).

my application will read all the data correctly (ive checked it with a breakpoint too and it reads all the different colors for the different ID's) but it wont display the text in the right color from the table. it will just display everything in the first color it comes across.

Im including my code if it helps. can anyone tell me where i am going wrong please?? (the procedures are called on the On_Page_Load method)

private

void Load_Events()
{
///<summary>
///Loads the events added from the NewEvent from into a dataset
///and then just as with the Holidyas, the events are wriiten to
///the appropriate calendar cell by comparing the date. only the
///title and time will be displayed in the cell. other event details
///such as, Objective, owner will be shown in a dialog box syle when
///the user hovers over the event.
///</summary>

mycn =new SqlConnection(strConn);
myda =new SqlDataAdapter("SELECT * FROM Event, EventTypeCategory WHERE Event.CategoryID = EventTypeCategory.CategoryID AND Event.Type = EventTypeCategory.CategoryType", mycn);
myda.Fill(ds2, "Events");
}

privatevoid Populate_Events(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
///<summary>
///This procedure will read all the data from the dataset - Events and then
///write each event to the appropriate calendar cell by comparing the date of
///the EventStartDate. if an event is found, the title and time are written
///to the cell, other details are shown by hovering over the cell to bring
///up another function that will display the data in a dialogBox. once the
///event is written, the appropriate color is applied to the text.
///</summary
if (!e.Day.IsOtherMonth)
{
foreach (DataRow drin ds2.Tables[0].Rows)
{
if ((dr["EventStartDate"].ToString() != DBNull.Value.ToString()))
{
DateTime evStDate = (DateTime)dr["EventStartDate"];
string evTitle = (string)dr["Title"];
string evStTime = (string)dr["EventStartTime"];
string evEnTime = (string)dr["EventEndTime"];
string evColor = (string)dr["CategoryColor"];

if(evStDate.Equals(e.Day.Date))
{
e.Cell.Controls.Add(new LiteralControl("<br>"));
e.Cell.Controls.Add(new LiteralControl("<FONT COLOR = evColor>"));
e.Cell.Controls.Add(new LiteralControl(evTitle + " " + evStTime + " - " + evEnTime));
}
}
}
}
else
{
e.Cell.Text = "";
}
}

e.Cell.Controls.Add(new LiteralControl("<FONT COLOR = " + evColor + ">"));

does that solve the problem ?

|||

Fantastic! works perfectly! Thanks!

No comments:

Post a Comment