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 :)

2 comments:

  1. wow, that's deep :) Funny I was actually able to understand it...I guess some of that computer language never leaves you...

    ReplyDelete
  2. So- I know this is a simple post but I'm glad you put it up... I've had to deal with this exact problem!

    ReplyDelete