 |
| 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
|
|
|
|

November 10th, 2006, 04:16 PM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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();
}
|
|

November 10th, 2006, 04:47 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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
|
|

November 10th, 2006, 05:01 PM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 12th, 2006, 01:40 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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
|
|

November 13th, 2006, 11:00 AM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 13th, 2006, 02:09 PM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

November 13th, 2006, 02:46 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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
|
|

November 13th, 2006, 04:11 PM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I tried to write the values out to the screen using Response.Write but all I get is System.Data.SqlClient.SqlDataReader.
|
|

November 13th, 2006, 05:01 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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
|
|

November 13th, 2006, 05:20 PM
|
|
Authorized User
|
|
Join Date: Dec 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I received the following error:
System.IndexOutOfRangeException: id
|
|
 |