473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Query String Problem\VB

I am trying to check whether a query string is being passed to my .aspx page, like so:

If Not Request.QueryString Is Nothing Then
If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then
Response.Redirect("../somepage.htm")
End If
Else
Response.Redirect("../somepage.htm")
End If

If there is a query string, everything is fine, but when there isn't one, the app crashes on the
second line :

If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then

:with this error:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an
object.

What I don't understand, is why is it getting passed this line anyway:

If Not Request.QueryString Is Nothing Then

:when there wasn't even a query string passed? Why didn't it jump down to the Else part, instead?

Thanks,
George
Nov 18 '05 #1
4 3088
Check for Request.QueryString.ToString() = string.empty

"George" <------@----.---> wrote in message
news:Sd*******************@bgtnsc04-news.ops.worldnet.att.net...
I am trying to check whether a query string is being passed to my .aspx page, like so:
If Not Request.QueryString Is Nothing Then
If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then
Response.Redirect("../somepage.htm")
End If
Else
Response.Redirect("../somepage.htm")
End If

If there is a query string, everything is fine, but when there isn't one, the app crashes on the second line :

If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then

:with this error:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

What I don't understand, is why is it getting passed this line anyway:

If Not Request.QueryString Is Nothing Then

:when there wasn't even a query string passed? Why didn't it jump down to the Else part, instead?
Thanks,
George

Nov 18 '05 #2
Hi George,

The point is that the QueryString property as such is always set and never
null (nothing). It is an object of NameValueCollection type that can have
zero elements (if query string is empty) but still is instantiated.

So, instead of checking the Request.QueryString existance, you should check
if it has the elemenent (field key) you are looking for:

string[] arString;
arString = Request.QueryString.GetValues("values");

if (arString != null)
{
...
}

Sorry for the c# code, but in nicely transposes to your VB.

--
Cezary Nolewajka
mailto:c.*********************@no-sp-am-eh-mail.com
remove all "no-sp-am-eh"s to reply
"George" <------@----.---> wrote in message
news:Sd*******************@bgtnsc04-news.ops.worldnet.att.net...
I am trying to check whether a query string is being passed to my .aspx page, like so:
If Not Request.QueryString Is Nothing Then
If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then
Response.Redirect("../somepage.htm")
End If
Else
Response.Redirect("../somepage.htm")
End If

If there is a query string, everything is fine, but when there isn't one, the app crashes on the second line :

If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then

:with this error:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

What I don't understand, is why is it getting passed this line anyway:

If Not Request.QueryString Is Nothing Then

:when there wasn't even a query string passed? Why didn't it jump down to the Else part, instead?
Thanks,
George


Nov 18 '05 #3
Anatoly,

Apparently, ToString is not available in that context. Thanks for the suggestion, though.

George

"Anatoly" <an*****@hotmail.com> wrote in message news:e1**************@TK2MSFTNGP10.phx.gbl...
Check for Request.QueryString.ToString() = string.empty

"George" <------@----.---> wrote in message
news:Sd*******************@bgtnsc04-news.ops.worldnet.att.net...
I am trying to check whether a query string is being passed to my .aspx

page, like so:

If Not Request.QueryString Is Nothing Then
If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then
Response.Redirect("../somepage.htm")
End If
Else
Response.Redirect("../somepage.htm")
End If

If there is a query string, everything is fine, but when there isn't one,

the app crashes on the
second line :

If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then

:with this error:

Exception Details: System.NullReferenceException: Object reference not set

to an instance of an
object.

What I don't understand, is why is it getting passed this line anyway:

If Not Request.QueryString Is Nothing Then

:when there wasn't even a query string passed? Why didn't it jump down to

the Else part, instead?

Thanks,
George


Nov 18 '05 #4
Cezary,

I tried what you suggested and that solved my problem! Learn something new everyday.

Thanks for your help.
George
"Cezary Nolewajka" <c.*********************@no-sp-am-eh-mail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi George,

The point is that the QueryString property as such is always set and never
null (nothing). It is an object of NameValueCollection type that can have
zero elements (if query string is empty) but still is instantiated.

So, instead of checking the Request.QueryString existance, you should check
if it has the elemenent (field key) you are looking for:

string[] arString;
arString = Request.QueryString.GetValues("values");

if (arString != null)
{
...
}

Sorry for the c# code, but in nicely transposes to your VB.

--
Cezary Nolewajka
mailto:c.*********************@no-sp-am-eh-mail.com
remove all "no-sp-am-eh"s to reply
"George" <------@----.---> wrote in message
news:Sd*******************@bgtnsc04-news.ops.worldnet.att.net...
I am trying to check whether a query string is being passed to my .aspx

page, like so:

If Not Request.QueryString Is Nothing Then
If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then
Response.Redirect("../somepage.htm")
End If
Else
Response.Redirect("../somepage.htm")
End If

If there is a query string, everything is fine, but when there isn't one,

the app crashes on the
second line :

If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then

:with this error:

Exception Details: System.NullReferenceException: Object reference not set

to an instance of an
object.

What I don't understand, is why is it getting passed this line anyway:

If Not Request.QueryString Is Nothing Then

:when there wasn't even a query string passed? Why didn't it jump down to

the Else part, instead?

Thanks,
George


Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Phil Powell | last post by:
if (document.location.href.indexOf('?') >= 0) document.location.href = document.location.href.substring(0, document.location.href.indexOf('?')); if (document.location.href.indexOf('#') >= 0) {...
3
by: Dr. Oz | last post by:
Hi, I am trying to read in a query string from one page and build a link to another page based on the query string. Here's the code I am using to read in the query string: <script...
4
by: Alan Lane | last post by:
Hello world: I'm including both code and examples of query output. I appologize if that makes this message longer than it should be. Anyway, I need to change the query below into a pivot table...
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
3
by: MLH | last post by:
Am repeating question with different subject heading, perhaps stating more clearly my problem... I have an A97 query (qryVehiclesNowners2) that has a table field in it named . Depending on the...
4
by: deko | last post by:
When using OutputTo with a query, the 'File name' window in the 'Output To' dialog gets populated with the name of the query by default. This makes the exported file self-describing if the query...
3
by: george.lengel | last post by:
Hello experts, I have been struggling for days to solve this problem and every suggestion I find via Google does not work for me. There is probably a solution out there that will do what I want,...
1
by: Oliver Bleckmann | last post by:
Damn, what's wrong here? CGI cgi; map<string,stringcgiParam = cgi.analyseCgiParam(); cout << cgiParam << endl; cout << cgiParam << endl; /////////////////////// #include <iostream>
2
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
How can I run this query against a table in my Access database? I don't know hwo to use it in C#. In VB I would use .Recordset = "some sql statement". How do I do this in C#? //I get a vlaue...
3
by: pbd22 | last post by:
Hi. I need some help with structuring my query strings. I have a form with a search bar and some links. Each link is a search type (such as "community"). The HREF for the link's anchor looks...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.