我现在有个表,数据用uniqueidentifier类型作为主键,现在想从一个列表中点击相应标题然后弹出新页面如article.aspx?id={0},但是接受页面如何获取这个参数呢? 我尝试使用Request.QueryString["id"].ToString().Trim(),好像不对,请问各位高手要怎么获取这个参数呢? 恩,同时最好能够防注入,改怎么写呢?百度了半天貌似没答案。测试中发现好像是SQL语句获得“3036657c-277c-476c-982d-75f154e09050”之类的字符串时那个“-”出错……新手不懂,请教各位大虾。先谢谢各位了。

解决方案 »

  1.   

    string strid = Request.QueryString["id"].ToString(); 
    Guid id = new Guid(strid); 
      

  2.   

    string id = "0c2027f5-818c-437e-be85-b4391e8e89af"; 
    Guid guid = new Guid(id); 
              
    SqlCommand cmd = new SqlCommand(sql, cnn); 
    cmd.Parameters.Add("@id", SqlDbType.UniqueIdentifier); 
    cmd.Parameters["@id"].Value = guid ; 
      

  3.   

    string sid = Request.QueryString["id"]; // 3036657c-277c-476c-982d-75f154e09050
    Guid guid = new Guid(sid); 
      

  4.   

    汗,我测试还是错误,烦请两位高手指点。我这样写:
    string UID = "26dea7c1-e16c-4bf1-8dd3-c555ab0307ca";
            Guid GID = new Guid(UID);
            using (SqlConnection conn = new SqlConnection(sConnectionString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand("SELECT * FROM tbGuestBook WHERE UID=" + GID, conn))
    提示:'dea7c1' 附近有语法错误。自己还是没看懂,都按两位的指点的用GUID处理了,还是出错。
      

  5.   

     using (SqlCommand cmd = new SqlCommand("SELECT * FROM tbGuestBook WHERE UID=" + GID, conn))改成 using (SqlCommand cmd = new SqlCommand("SELECT * FROM tbGuestBook WHERE UID='" + GID+"'", conn))
    试一下
      

  6.   

    传值要编码:
    article.aspx?id=HttpUtility.HtmlEncode("id");接受的时候要解码:
    string a=HttpUtility.HtmlDecode(Request.QueryString["id"].ToString().Trim());
      

  7.   

    我擦...Google了半天,找到这个答案了....非常感谢5楼兄弟...