Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 10th, 2006, 04:16 PM
Authorized User
 
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdove84
Default ID column used to redirect page

I have a button on a page that is used for redirection. When a user clicks the button, I have input code that is meant to check a database's ID column and determine if there are ten entries. However, when I test the code it using a Breakpoint it seems to ignore the IF/ELSE. I did check the SELECT statement out on the actual database and it produce the correct results.

Here's the code:

SqlConnection sqlConn = new SqlConnection ConfigurationSettings.AppSettings["conn"]);
sqlConn.Open();

SqlDataReader sqlDR;

SqlCommand sqlCmd = new SqlCommand();
sqlCmd = new SqlCommand("SELECT (ID) FROM middle", sqlConn);
sqlDR = sqlCmd.ExecuteReader();

if(sqlDR.HasRows==true)
{
    while(sqlDR.Read())
    {
        if(id==11)
        {
            Response.Redirect("RegFull.aspx");
        }
        else
        {
            Response.Redirect("Registration.aspx"); }
    }
    sqlDR.Close();
    sqlConn.Close();
}




 
Old November 10th, 2006, 04:47 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Does your code enter your while? Logically speaking, if it enters the While loop SOMETHING is going to happen.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old November 10th, 2006, 05:01 PM
Authorized User
 
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdove84
Default

Yes, the code does enter the WHILE. I did notice something I hadn't before. In the Autos listing as I F11 through code from the breakpoint the id integer's value was staying at a constant zero which I assume means that my SELECT statement is not retrieving all of the values listed in the database.

rdove84


 
Old November 12th, 2006, 01:40 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I am curious, you have the integer value ID and you are checking to see if it equals 11 but, no where in your code do i see where you are assigning a value to ID.

Try this as your if condition:

if(Convert.ToInt32(sqlDR["id"]) == 11){
}

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old November 13th, 2006, 11:00 AM
Authorized User
 
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdove84
Default

Thank you for your help. I ran the new code piece, but the breakpoint is still showing that the "id" is not coming up with a value.

I went back over the code using a breakpoint to determine the different line values and see if I could find anything again.

The sqlCmd.ExecuteReader(), Convert.ToInt32(), and Response.Redirect are all overloaded, is this normal?

rdove84

 
Old November 13th, 2006, 02:09 PM
Authorized User
 
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdove84
Default

I went in an attempted to add a Parameter based on some other information that I found. When I did I got an error message that said, "Invalid attempt to read when no data present." However, other information I have found says that if the sqlDR.HasRows comes back with a value of the true then it is finding data.

Any ideas?

rdove84

 
Old November 13th, 2006, 02:46 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I use datareaders only to fetch my data and populate a Datatable (by and large) so I have never used HasRows. Are you certain data is being returned by the above query? Is it returning rows of NULL values? Remove your IF statement and in your while, write the values of you datareader out to the screen, see if you are getting anything.

It seems, though, you are not getting any data back.

hth

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old November 13th, 2006, 04:11 PM
Authorized User
 
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdove84
Default

I tried to write the values out to the screen using Response.Write but all I get is System.Data.SqlClient.SqlDataReader.

 
Old November 13th, 2006, 05:01 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Try this.
Response.Write(sqlDR["id"].ToString());

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old November 13th, 2006, 05:20 PM
Authorized User
 
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rdove84
Default

I received the following error:

System.IndexOutOfRangeException: id







Similar Threads
Thread Thread Starter Forum Replies Last Post
identity column id find!! keyvanjan Classic ASP Basics 7 January 20th, 2007 01:12 PM
redirect to page other than default page sarah lee ASP.NET 1.0 and 1.1 Basics 3 December 15th, 2006 05:45 PM
Pass ID to redirect page? okboy ASP.NET 2.0 Basics 2 December 14th, 2006 06:12 PM
Redirect to new page without closing current page peter2004 ASP.NET 2.0 Basics 5 June 5th, 2006 08:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.