如何从 vb.net 中的 request.querystring 获取值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1520536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 14:27:42  来源:igfitidea点击:

How to get the value from request.querystring in vb.net

vb.net

提问by Manoj Singh

I am using VB.NET

我正在使用 VB.NET

My problem is that, I have got below request.querystring

我的问题是,我有以下 request.querystring

http://localhost/ISS/Training/TrainingUpdate.aspx?cpuserid='50'&%20courseid='6'&%20status='accept'

Now I want to pass all the above three querystring in a sql stored procedure parameter.

现在我想在 sql 存储过程参数中传递所有上述三个查询字符串。

for example,

例如,

Try
                Dim conString As String = WebConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString
                Dim con As New SqlConnection(conString)
                con.Open()
                Dim cmd As SqlCommand
                cmd = New SqlCommand("uspUpdateDelegateAcceptDeclineStatus", con)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@CPUserID", SqlDbType.Int).Value = Request.QueryString("cpuserid")
                cmd.Parameters.Add("@CourseID", SqlDbType.Int).Value = Request.QueryString("courseid")
                cmd.Parameters.Add("@StatusName", SqlDbType.Int).Value = Request.QueryString("status")
                cmd.ExecuteNonQuery()
            Catch ex As Exception
                ErrorHandler.WriteError(ex.Message)
            End Try

But I am able to get the request querystring value in my parameter.

但是我能够在我的参数中获取请求查询字符串值。

Please suggest.

请建议。

Thanks.

谢谢。

Best Regards, Yuv

最好的问候,尤夫

采纳答案by Justin Niessner

For one, it looks like you have some extra spaces in your URL (specifically in the QueryString...marked by %20).

一方面,您的 URL 中似乎有一些额外的空格(特别是在 QueryString 中...标记为 %20)。

Not sure if that would throw things off or not, but it's a possibility.

不确定这是否会导致事情失败,但这是一种可能性。

回答by Joel Coehoorn

Get rid of the extra '%20' (spaces) in the query string (if you can). If that's not an option, then remember that they are part of the query string, and so you'll need to include that when you access the values:

去掉查询字符串中多余的“%20”(空格)(如果可以的话)。如果这不是一个选项,那么请记住它们是查询字符串的一部分,因此您需要在访问值时包含它:

Request.QueryString(" cpuserid")