Reputation: 485
I have a dropdownlist selection, selected value will be ID, type is GUID, currently my code for the select button is
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Selection As String = Nothing
If Not DropDownList3.SelectedValue Is Nothing Then Selection = DropDownList3.SelectedValue
Session("Selected") = Selection
End Sub
then I have
Dim ID is guid
ID = Session("Selected")
then i need to execute sql such as select * from .. where ID=..
Problem happens at ID = Session("Selected")
, as ID
is GUID
, while Session("Selected")
is string
I wonder if there is a way to handle it?
Thanks very much for help!
Upvotes: 1
Views: 1500
Reputation: 894
Try this method:
GUID myGuid;
object myObj = Session("Selected");
if (myObj != null && Guid.TryParse(myObj.ToString(), out myGuid))
{
//input is good, do stuff here
}
else
{
//input is bad, handle error
}
I hope this helps. Good luck.
Upvotes: 4