asp.net 如何在c#中传递浮点类型到url?

mf98qq94  于 2023-03-20  发布在  .NET
关注(0)|答案(3)|浏览(127)

在客户端:

<script type="text/javascript">
    function ShowDetailPopup(FPS_Code, PhaseNo) {
      popup.SetContentUrl("test4.aspx?id=" + FPS_Code + "&PhaseNo=" + PhaseNo);
      popup.Show();
    }
</script>

在服务器端:

using (SqlConnection con = new SqlConnection(strcon1))
{
    SqlCommand cmd = new SqlCommand("SELECT ID,DocumentNo,ReleaseNo,PhaseNo,FPS_Code,DrawingNo  FROM   Project1 WHERE FPS_Code=@FPS_Code and PhaseNo=@PhaseNo");

    cmd.Parameters.AddWithValue("@FPS_Code", Request.QueryString["id"].ToString());
    cmd.Parameters.AddWithValue("@PhaseNo", Request.QueryString["PhaseNo"]);

    cmd.CommandType = CommandType.Text;
    cmd.Connection = con;
    con.Open();
    SqlDataReader sdr = cmd.ExecuteReader();
    while (sdr.Read())
    {
        ASPxLabel1.Text = sdr["ID"].ToString();
        ASPxLabel2.Text = sdr["ReleaseNo"].ToString();
        ASPxLabel3.Text = sdr["PhaseNo"].ToString();
        ASPxLabel4.Text = sdr["DrawingNo"].ToString();
        ASPxLabel5.Text = sdr["FPS_Code"].ToString();
       
    }

    con.Close();

}

r9f1avp5

r9f1avp51#

SqlCommand添加参数时,可以指定Float数据类型,如下所示:

cmd.Parameters.Add("@FPS_Code", SqlDbType.Float, 20).Value = Request.QueryString["id"];
yqkkidmi

yqkkidmi2#

只需使用URL转义如下:

<script type="text/javascript">
    function ShowDetailPopup(FPS_Code, PhaseNo) {
      popup.SetContentUrl(encodeURIComponent("test4.aspx?id=" + FPS_Code + "&PhaseNo=" + PhaseNo));
      popup.Show();
    }
</script>
7dl7o3gd

7dl7o3gd3#

必须将PhaseNo字符串转换为双精度。将该行

cmd.Parameters.AddWithValue("@PhaseNo", Request.QueryString["PhaseNo"]);

cmd.Parameters.AddWithValue("@PhaseNo", System.Convert.ToDouble(Request.QueryString["PhaseNo"]));

相关问题