如何在C#中获取带有查询字符串ID的匹配值 [英] how to get matching values with querystring id in c#

查看:456
本文介绍了如何在C#中获取带有查询字符串ID的匹配值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人告诉我如何在c#中获取与querystring id匹配的值,我能够在vb.net中执行代码,但是我的代码在使用c#编码与查询字符串时抛出错误,我的代码是

Pls someone tell that how to get matching values with querystring id in c#, i am able to do code in vb.net but my code is throwing error with c# coding with query string, my code is

If Request.QueryString("ID") <> "" AndAlso Request.QueryString("ID") IsNot Nothing Then
                'Dim cmd As New SqlClient.SqlCommand("SELECT * FROM news WHERE id=" + Request.QueryString("ID"), sqlcon)
                If Request.QueryString("ID") = 1 Then
                    ada = New SqlClient.SqlDataAdapter("SELECT * from teammanage where saveas='Under 10'", sqlcon)
                    dt = New DataTable("dell")
                    ada.Fill(dt)
                    If dt.Rows.Count > 0 Then
                        tit = dt.Rows(0)("name").ToString()
                        detail = dt.Rows(0)("photo").ToString()
                    End If




请有人告诉我如何在c#中执行代码,以及如何在数据列表中显示.

请帮助纠正此代码.




Pls someone tell that how to do code in c#, and how to display in datalist.

Pls help to correct this code.

推荐答案

您需要使用Request.QueryString["ID"]来获取URL中定义的参数.

有关详细信息,请参见此处:使用QueryString在页面之间传递变量 [
You need to use Request.QueryString["ID"] to get the parameters defined in the URL.

Here for details: Passing variables between pages using QueryString[^]


尝试以下方式


try that in the following way


if (Request.QueryString["CatId"] != null)
                {
                   if(Convert.ToInt32(Request.QueryString["CatId"])==2)
                  {
                           //Your Code
                  }

                }


这篇关于如何在C#中获取带有查询字符串ID的匹配值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆