Friday, February 20, 2009

Guids and c#

OK So finally i thought i should write my first post, so there it goes,

Sometimes small problems end up taking way longer time that you would think,

I have been trying to set selected value of rad combo box to a value matching my DataBase value,

as follows,

DataSet ds = cs.GetUserID(new Guid(Session["CompanyID"].ToString()));
if (!(ds.Tables[0].Rows[0]["UserID"].Equals(DBNull.Value)))
ddlContact.SelectedValue = ds.Tables[0].Rows[0]["UserID"].ToString();

Did'nt realise that C# on the most part is case sensative and Guids are saved in CAPS in SQL Database, so this wasnt working...

==> Just Added .ToUpper() and it work as follows,

DataSet ds = cs.GetUserID(new Guid(Session["CompanyID"].ToString()));
if (!(ds.Tables[0].Rows[0]["UserID"].Equals(DBNull.Value)))
ddlContact.SelectedValue = ds.Tables[0].Rows[0]["UserID"].ToString().ToUpper();

Thought i should share :)