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 June 2nd, 2006, 05:53 PM
Authorized User
 
Join Date: Dec 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Anyone HELP error ASP.NET in C#

The error displayed on my .aspx page is shown below. Please I am trying to develop a Login page. But constantly I am receiving this error.

 No data exists for the row/column.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: No data exists for the row/column.

Source Error:

Line 48: //Verify the returned row for case-sensitivity
Line 49:
Line 50: if (txtPass.Text == reader["Pass"].ToString())
Line 51: {
Line 52: FormsAuthentication.RedirectFromLoginPage(txtUser. Text, false);


Source File: c:\Application development website\links\login.aspx Line: 50

Stack Trace:

[InvalidOperationException: No data exists for the row/column.]
   System.Data.OleDb.OleDbDataReader.DoValueCheck(Int 32 ordinal) +48
   System.Data.OleDb.OleDbDataReader.GetValue(Int32 ordinal) +9
   System.Data.OleDb.OleDbDataReader.get_Item(String name) +24
   ASP.login_aspx.login_click(Object sender, EventArgs e) in c:\Application development website\links\login.aspx:50
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75
   System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +97
   System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919


THIS IS MY CODE:

public void login_click(object sender, EventArgs e)
       {

           OleDbConnection conn1 = new OleDbConnection();
           string myconn;
           myconn = "Provider=Microsoft.Jet.OLEDB.4.0;";
        myconn += "Data Source= " + Server.MapPath ("accessMyWebsite.mdb");
          conn1.ConnectionString = myconn;


          string auth;
          auth = "SELECT User, Pass FROM Customer WHERE Name='";
          auth += txtUser.Text + "' AND Pass='";
          auth += txtPass.Text + "'";

    //Define ADO.NET objects

                      OleDbCommand dbCommand1 = new OleDbCommand();
                      dbCommand1.CommandText = auth;
                      dbCommand1.Connection = conn1;
                      conn1.Open();
                      dbCommand1.ExecuteNonQuery();
                      conn1.Close();



           try

           {

               conn1.Open();
               OleDbDataReader reader = dbCommand1.ExecuteReader();
               reader.Read();


               //Verify the returned row for case-sensitivity

               if (txtPass.Text == reader["Pass"].ToString())
               {
                   FormsAuthentication.RedirectFromLoginPage(txtUser. Text, false);
               }
               else
               {
                   loginfailed.Text = "Reader Invalid Login";
               }
               reader.Close();
           }


           finally
           {
               conn1.Close();
           }
       }



 
Old June 2nd, 2006, 05:56 PM
Authorized User
 
Join Date: Dec 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This actualy is my authentication page for my website with backend Access database

 
Old June 4th, 2006, 01:55 PM
Authorized User
 
Join Date: Dec 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Anyone how to solve the problem???

 
Old June 4th, 2006, 05:04 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You need to make sure that your query returns a record, before you try to access it. You can do this by checking the return value of the Read method. Try this:
Code:
if (reader.Read())
{
  if (txtPass.Text == reader["Pass"].ToString())
  {
    FormsAuthentication.RedirectFromLoginPage(txtUser.Text, false);
  }
  else
  {
    loginfailed.Text = "Reader Invalid Login";
  }
}
reader.Close();
Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Praise You by Fatboy Slim (From the album: You've Come a Long Way, Baby) What's This?
 
Old June 5th, 2006, 08:58 PM
Authorized User
 
Join Date: Dec 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Imar is working. If you need the code tell me.






Similar Threads
Thread Thread Starter Forum Replies Last Post
asp.net hosting error compad ASP.NET 2.0 Professional 0 September 16th, 2008 03:25 AM
Error in Migrating Project from ASP to ASP.NET hbansal ASP.NET 1.0 and 1.1 Professional 0 September 12th, 2008 05:48 AM
ASP.NET ERROR rsm42 ASP.NET 1.0 and 1.1 Basics 0 December 24th, 2006 07:49 AM
ASP.NET Error vjain1 VS.NET 2002/2003 2 April 20th, 2005 12:52 PM
ASP.NET Using VB.NET Chapt 3 Code error? uh6uj All Other Wrox Books 1 February 26th, 2004 10:46 AM





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