将varchar转换为唯一标识符 [英] Convert varchar to unique identifier
本文介绍了将varchar转换为唯一标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个临时数据表,单击保存"按钮时,该临时值将保存到数据库中.
现在,我想将值另存为MS SQL数据库中的唯一标识符.
而且,当我想在gridview中查看数据库表时,我想在gridview中将uniqueidentifier值查看为varchar.
有想法吗?
这是我保存到数据库的代码(.cs)
Hi,
I have a temporary data table, where when I click the save button,the temporary values will be saved into database.
Now I want to save the values as a unique identifier in MS SQL database.
And when I want to view the database table in gridview, I want to view the uniqueidentifier values as varchar in gridview.
Any ideas guys?
Here''s my save to database code (.cs)
protected void BtnSendToDatabase_Click(object sender, EventArgs e)
{
string strId = string.Empty;
for (int count = 0; count < dt.Rows.Count; count++)
{
strId = strId + dt.Rows[count][0].ToString() + ", ";
}
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT INTO Table1 (Company_Name) VALUES ('" + strId + "')";
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
推荐答案
将Unique Identifier
存储到数据库中的第一个问题,
为此,请确保您的值可以转换为Guid
,因为Unique Identifier
具有Guid
格式值.
例如
格式:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
样本:6F9619FF-8B86-D011-B42D-00C04FC964FF
另一个问题是要在gridview
中将Unique Identifier
检索为String
,
这将由gridview
处理,您不需要为此付出任何额外的努力.
如果有帮助,请 投票 和 接受答案 .
The first question to store theUnique Identifier
into database,
for that make sure your value can be converted toGuid
, BecauseUnique Identifier
havingGuid
format value.
e.g.
Format :xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Sample :6F9619FF-8B86-D011-B42D-00C04FC964FF
The other question was about to retriveUnique Identifier
as aString
ingridview
,
That will be handled bygridview
you dont need any extra effor for that.
Please vote and Accept Answer if it Helped.
这篇关于将varchar转换为唯一标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文