Guid uid=new Guid(yourstring)

解决方案 »

  1.   

    设置GridView的DataKeyNames属性为你的“ID”值,然后在程序里通过如下的方式来获取你的Guid值:object objValue = this.gridView1.DataKeys[rowIndex].Value;
    if (objValue is Guid)
    {
        Guid guid = (Guid)objValue;
    }
      

  2.   

    各位,你们没理解我的意思啊,我现在是要做更新数据.
    我想知道:                uniqueidentifier.userID; 
                    string   userID,userLogName,   username,   sex,   phone,   mobilephone,   sysdate; 
                    userID   =uniqueidentifier.parse   (GridView1.Rows[e.RowIndex]. 
    这个地方该怎么写.因为原来userID是int型这样的写法是可以的啊,但是uniqueidentifier不支持这样的写法啊.
      

  3.   

    uniqueidentifier不就是GUID类型嘛你给userID赋GUID类型就行了Guid userID=new Guid(GridView1.Rows[e.RowIndex].Value);
      

  4.   

    改成这样编译提示:说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: 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].
     
      

  5.   

    汗,重复定义啦,下面定义了上面就不用啦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类型哦,别搞个类型不对的来
      

  6.   

    编译错误 
    说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: 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
      

  7.   

    在new有波浪线提示:无法将类型"string"隐式转换为"system.Guid"在GridView1有波浪线提示:无法从"system.web.ui.control"转换为"byte[]"
      

  8.   

    错误提示多明确啊
    Guid userID=new Guid(里面需要是string类型的)
    你这样左边是GUID类型右边是string类型你觉得能行么?Guid   userID   =   new   Guid(GridView1.Rows[e.RowIndex].Cells[0].Controls[0].ToString()); 不知道你存储过程里面userid参数类型是什么,这样写的话就必须是uniqueidentifier
      

  9.   

    我在更新的时候提示:GUID 应包含带 4 个短划线的 32 位数(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)。
    我的数据结构是  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
      

  10.   

    错误很明显啊,GridView1.Rows[e.RowIndex].Cells[0].Controls[0].ToString()不是guid格式的字符,
    你跟踪一下看看GridView1.Rows[e.RowIndex].Cells[0].Controls[0].ToString()是什么吧.