uniqueidentifier 为ID时怎么转换实更新数据库?? Guid uid=new Guid(yourstring) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 设置GridView的DataKeyNames属性为你的“ID”值,然后在程序里通过如下的方式来获取你的Guid值:object objValue = this.gridView1.DataKeys[rowIndex].Value;if (objValue is Guid){ Guid guid = (Guid)objValue;} 各位,你们没理解我的意思啊,我现在是要做更新数据.我想知道: uniqueidentifier.userID; string userID,userLogName, username, sex, phone, mobilephone, sysdate; userID =uniqueidentifier.parse (GridView1.Rows[e.RowIndex]. 这个地方该怎么写.因为原来userID是int型这样的写法是可以的啊,但是uniqueidentifier不支持这样的写法啊. uniqueidentifier不就是GUID类型嘛你给userID赋GUID类型就行了Guid userID=new Guid(GridView1.Rows[e.RowIndex].Value); 改成这样编译提示:说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS0128: 已在此范围定义了名为“userID”的局部变量。源错误: 行 170:行 171: string userID,userLogName, username, sex, phone, mobilephone, sysdate;行 172: Guid userID=new Guid(GridView1.Rows[e.RowIndex].行 173: Cells[0].Controls[0]).ToString;行 174: userLogName = ((TextBox)GridView1.Rows[e.RowIndex]. 汗,重复定义啦,下面定义了上面就不用啦string userLogName, username, sex, phone, mobilephone, sysdate; Guid userID=new Guid(GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).ToString); 其中GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).ToString的值一定要是Guid类型哦,别搞个类型不对的来 编译错误 说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS1502: 与“System.Guid.Guid(byte[])”最匹配的重载方法具有一些无效参数源错误: 行 170:行 171: string userLogName,username, sex, phone, mobilephone, sysdate;行 172: Guid userID = new Guid(GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).ToString();行 173: userLogName = ((TextBox)GridView1.Rows[e.RowIndex].行 174: Cells[1].Controls[0]).Text; 肯定是uniqueidentifier我写后是这样的: String strConnection = ConfigurationSettings.AppSettings["connstring"]; SqlConnection myConnection = new SqlConnection(strConnection); SqlCommand cm = new SqlCommand("updateu", myConnection); cm.CommandType = CommandType.StoredProcedure; cm.Connection.Open(); string userLogName,username, sex, phone, mobilephone, sysdate; Guid userID = new Guid(GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).ToString(); userLogName = ((TextBox)GridView1.Rows[e.RowIndex]. Cells[1].Controls[0]).Text; username = ((TextBox)GridView1.Rows[e.RowIndex]. Cells[3].Controls[0]).Text; sex = ((TextBox)GridView1.Rows[e.RowIndex]. Cells[4].Controls[0]).Text; phone = ((TextBox)GridView1.Rows[e.RowIndex]. Cells[5].Controls[0]).Text; mobilephone = ((TextBox)GridView1.Rows[e.RowIndex]. Cells[5].Controls[0]).Text; sysdate = ((TextBox)GridView1.Rows[e.RowIndex]. Cells[6].Controls[0]).Text 在new有波浪线提示:无法将类型"string"隐式转换为"system.Guid"在GridView1有波浪线提示:无法从"system.web.ui.control"转换为"byte[]" 错误提示多明确啊Guid userID=new Guid(里面需要是string类型的)你这样左边是GUID类型右边是string类型你觉得能行么?Guid userID = new Guid(GridView1.Rows[e.RowIndex].Cells[0].Controls[0].ToString()); 不知道你存储过程里面userid参数类型是什么,这样写的话就必须是uniqueidentifier 我在更新的时候提示:GUID 应包含带 4 个短划线的 32 位数(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)。我的数据结构是 uniqueidentifierCREATE TABLE [dbo].[users] ( [userID] uniqueidentifier ROWGUIDCOL NOT NULL , [userLogName] [nvarchar] (30) COLLATE Chinese_PRC_CI_AS NOT NULL , [userName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL , [Sex] [nvarchar] (4) COLLATE Chinese_PRC_CI_AS NULL , [Phone] [nvarchar] (18) COLLATE Chinese_PRC_CI_AS NULL , [mobilephone] [nvarchar] (12) COLLATE Chinese_PRC_CI_AS NULL ,) ON [PRIMARY]GO 错误很明显啊,GridView1.Rows[e.RowIndex].Cells[0].Controls[0].ToString()不是guid格式的字符,你跟踪一下看看GridView1.Rows[e.RowIndex].Cells[0].Controls[0].ToString()是什么吧. 采用VPN网络 在IIS发布ASP.NET网站 vs2008的一个BUG,突然所有的内容都变成 电子商务网站数据库设计 asp.net 总是出错 asp.net页面回传 如何做一个动态的DataList 高分求解:Jmail 接收 Email 的难题! 动态生成网页,.aspx 和.aspx.cs 文件 是不是要动态重新编译项目,如何编译??(100分) asp.net网站部署时的webconfig里一些节点没有识别 asp.net 服务器图片 显示问题,急等解决 关于泛型的问题 javascript问题,问过一次,没有答案,厚着脸皮问第2次。《孟子一章》
if (objValue is Guid)
{
Guid guid = (Guid)objValue;
}
我想知道: uniqueidentifier.userID;
string userID,userLogName, username, sex, phone, mobilephone, sysdate;
userID =uniqueidentifier.parse (GridView1.Rows[e.RowIndex].
这个地方该怎么写.因为原来userID是int型这样的写法是可以的啊,但是uniqueidentifier不支持这样的写法啊.
行 171: string userID,userLogName, username, sex, phone, mobilephone, sysdate;
行 172: Guid userID=new Guid(GridView1.Rows[e.RowIndex].
行 173: Cells[0].Controls[0]).ToString;
行 174: userLogName = ((TextBox)GridView1.Rows[e.RowIndex].
Guid userID=new Guid(GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).ToString);
其中
GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).ToString的值一定要是Guid类型哦,别搞个类型不对的来
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS1502: 与“System.Guid.Guid(byte[])”最匹配的重载方法具有一些无效参数源错误: 行 170:
行 171: string userLogName,username, sex, phone, mobilephone, sysdate;
行 172: Guid userID = new Guid(GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).ToString();
行 173: userLogName = ((TextBox)GridView1.Rows[e.RowIndex].
行 174: Cells[1].Controls[0]).Text;
肯定是uniqueidentifier我写后是这样的: String strConnection = ConfigurationSettings.AppSettings["connstring"];
SqlConnection myConnection = new SqlConnection(strConnection); SqlCommand cm = new SqlCommand("updateu", myConnection);
cm.CommandType = CommandType.StoredProcedure;
cm.Connection.Open(); string userLogName,username, sex, phone, mobilephone, sysdate;
Guid userID = new Guid(GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).ToString();
userLogName = ((TextBox)GridView1.Rows[e.RowIndex].
Cells[1].Controls[0]).Text;
username = ((TextBox)GridView1.Rows[e.RowIndex].
Cells[3].Controls[0]).Text;
sex = ((TextBox)GridView1.Rows[e.RowIndex].
Cells[4].Controls[0]).Text;
phone = ((TextBox)GridView1.Rows[e.RowIndex].
Cells[5].Controls[0]).Text;
mobilephone = ((TextBox)GridView1.Rows[e.RowIndex].
Cells[5].Controls[0]).Text;
sysdate = ((TextBox)GridView1.Rows[e.RowIndex].
Cells[6].Controls[0]).Text
Guid userID=new Guid(里面需要是string类型的)
你这样左边是GUID类型右边是string类型你觉得能行么?Guid userID = new Guid(GridView1.Rows[e.RowIndex].Cells[0].Controls[0].ToString()); 不知道你存储过程里面userid参数类型是什么,这样写的话就必须是uniqueidentifier
我的数据结构是 uniqueidentifier
CREATE TABLE [dbo].[users] (
[userID] uniqueidentifier ROWGUIDCOL NOT NULL ,
[userLogName] [nvarchar] (30) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[userName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[Sex] [nvarchar] (4) COLLATE Chinese_PRC_CI_AS NULL ,
[Phone] [nvarchar] (18) COLLATE Chinese_PRC_CI_AS NULL ,
[mobilephone] [nvarchar] (12) COLLATE Chinese_PRC_CI_AS NULL ,) ON [PRIMARY]
GO
你跟踪一下看看GridView1.Rows[e.RowIndex].Cells[0].Controls[0].ToString()是什么吧.