我有一个下拉列表选项,选中的值将是ID,类型是GUID,目前我的选择按钮的代码是
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
然后我
Dim ID is guid
ID = Session("Selected")
然后我需要执行select * from .. where ID=..
等sql
问题发生在ID = Session("Selected")
,ID
为GUID
,而Session("Selected")
为string
我想知道是否有办法处理它?
非常感谢您的帮助!
答案 0 :(得分:3)
试试这个方法:
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
}
我希望这会有所帮助。祝你好运。