将guid转换为字符串,反之亦然 [英] converting guid to string and vice- versa
问题描述
大家好
我有一个标签lblUID,我正在其中填充具有数据类型唯一标识符的db表的id.如何将lblUID.Text从Guid转换为字符串,然后再次将字符串转换为Guid.以及如何检查其是否为空,如IsNullOrEmpty in字符串?我必须使用此方法-
hey everyone
I have a label lblUID on which i am populating id of db table which has data type unique identifier.How can i convert lblUID.Text from Guid to string and again string to Guid.And how to check whether its empty or not like IsNullOrEmpty in string?i have to use this method--
if (RadGrid1.SelectedItems.Count != 0)
{
txtItemNamePanel.Focus();
pnlExternalForm.Visible = true;
RadGrid Grid = (this.FindControl("RadGrid1") as RadGrid);
string Pid = Convert.ToString(Grid.SelectedValues["Pid"]);
string query = "SELECT * FROM tblProducts where Pid=" + Pid;
GetProductInfoForEdit(query, Pid);
BindGrid();
}
除了我用UID代替唯一标识符pid之外.
lblIdPanel.Text = ProductId;应该等于UID.
谢谢
Amit
except for i have UID in place of pid that is unique identifier.
lblIdPanel.Text = ProductId; should be equal to UID.
Thanks
Amit
推荐答案
我的意思是:
i mean:
<pre>string str = "cd7fc78e-de3c-4761-9192-4cfb7a6088e5";
Guid g = new Guid(str);
检查Guid对象是否为空.
Check to see if the Guid object is null.
Guid guid = Guid.NewGuid();
if (quid == null)
{
// do something
}
要将其转换为字符串(将参数传递给ToString()方法会导致以特定方式设置返回值的格式,请参见此处: ^ ]):
To convert it to a string (passing paramneters to the ToString() method causes the returned value to formatted in specific ways see here: http://msdn.microsoft.com/en-us/library/97af8hh4.aspx[^]):
string myGuid = guid.ToString();
要将字符串转换为GUID:
To convert a string to a guid:
Guid guid = new Guid(myguidstring);
如果您用Google搜索过,就会发现以下内容:
http://msdn.microsoft.com/en-us/library/system.guid.aspx [^ ]
它只需要一点点主动性和常识,即可节省大量时间等待别人回答您的问题.
If you had googled it, you would have found this:
http://msdn.microsoft.com/en-us/library/system.guid.aspx[^]
All it takes is a little initiative and common sense to save yourself buttloads of time waiting for someone to answer your question.
lblIdPanel.Text = ProductId.ToString();
这篇关于将guid转换为字符串,反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!