Please Help Me - object reference not set to an instance

G

Guest

hello all,
I am new to C# and ASP, I am trying to build and applicationwith a login in
page. I followed an example from a book to create his page but I am havin
problem when i run the program.
I know there has been a thread like this in this forum but the suggestion I
have tried does not correct this problem. please have a look at the code belo
and help me.need help urgently. you help is much appreciated.
When i run the run I get this error in the browser, Object reference not set
to an instance of an object"
The error is on the line coloured red - dataReader =
oleDbDataAdapter1.SelectCommand.ExecuteReader();

'------code from program---------

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.OleDb;
namespace WebsupportProject
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
/// allow authorised users to login
public class Login : System.Web.UI.Page
{
protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
protected System.Data.OleDb.OleDbConnection oleDbConnection1;
protected System.Data.OleDb.OleDbDataReader dataReader;
//web form labels
protected System.Web.UI.WebControls.Label lbpassword;
protected System.Web.UI.WebControls.Label lbauthorisedusername;
protected System.Web.UI.WebControls.Label lbprompt;
protected System.Web.UI.WebControls.DropDownList authorisedusernameList;
protected System.Web.UI.WebControls.Button submitButton;
protected System.Web.UI.WebControls.RequiredFieldValidator
requiredPasswordValidator;
protected System.Web.UI.WebControls.CustomValidator invalidPasswordValidator;
protected System.Web.UI.WebControls.TextBox passwordTxtBox;
protected System.Web.UI.WebControls.Label promptlabel;
protected System.Web.UI.WebControls.DropDownList authourisedusernameList;
protected System.Web.UI.WebControls.Label passwordLabel;
protected System.Web.UI.WebControls.TextBox passwordTextBox;

//Page Loader
//Reading the list of user names from authoriseduser table
private void Page_Load(object sender, System.EventArgs e)
{
if ( !IsPostBack )
{
//open Database
oleDbConnection1.Open();
//execute query
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader(); ' line of error
// add first authorisedusername to the list
while ( dataReader.Read() )
authorisedusernameList.Items.Add( dataReader.GetString( 0 ) );

// close database connection
oleDbConnection1.Close();
}
// Put user code to initialize the page here
} // end of Page_Load
private void invalidPasswordValidator_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args )
{
//open database connection
oleDbConnection1.Open();

oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM AuthorisedUsers
WHERE LoginName = '" +
Request.Form[ "authorisedusernameList" ].ToString() + "'";
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();
dataReader.Read();
//if password is correct create authentication ticketfor user
if ( args.Value == dataReader.GetString( 1 ) )
{
FormsAuthentication.SetAuthCookie(
Request.Form[ "authorisedusernameList" ], false);
Session.Add( "name", Request.Form[ "authorisedusernameList" ].ToString());
Response.Redirect( "LoggedCall.apsx" );
}
else
args.IsValid=false;
//close database connection
oleDbConnection1.Close();
}// end method invalidPasswordValidator_ServerValidate
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = @"Integrated Security=SSPI;Packet
Size=4096;Data Source=""ERYCKOP-002"";Tag with column collation when
possible=False;Initial Catalog=Project;Use Procedure for Prepare=1;Auto
Translate=True;Persist Security
Info=False;Provider=""SQLOLEDB.1"";Workstation ID=""ERYCKOP-002"";Use
Encryption for Data=False";
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion


}//end class login
}
----end of code------

any help is much needed.
Thank you
 
G

Guest

In your statement
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();

the adapter does not have a selectCommand at this point.

You will have to do:
oleDbDataAdapter1.SelectCommand = <some sql query>


Regards,

Deepak
[I Code, therefore I am]


kojosmooth said:
hello all,
I am new to C# and ASP, I am trying to build and applicationwith a login in
page. I followed an example from a book to create his page but I am havin
problem when i run the program.
I know there has been a thread like this in this forum but the suggestion I
have tried does not correct this problem. please have a look at the code belo
and help me.need help urgently. you help is much appreciated.
When i run the run I get this error in the browser, Object reference not set
to an instance of an object"
The error is on the line coloured red - dataReader =
oleDbDataAdapter1.SelectCommand.ExecuteReader();

'------code from program---------

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.OleDb;
namespace WebsupportProject
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
/// allow authorised users to login
public class Login : System.Web.UI.Page
{
protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
protected System.Data.OleDb.OleDbConnection oleDbConnection1;
protected System.Data.OleDb.OleDbDataReader dataReader;
//web form labels
protected System.Web.UI.WebControls.Label lbpassword;
protected System.Web.UI.WebControls.Label lbauthorisedusername;
protected System.Web.UI.WebControls.Label lbprompt;
protected System.Web.UI.WebControls.DropDownList authorisedusernameList;
protected System.Web.UI.WebControls.Button submitButton;
protected System.Web.UI.WebControls.RequiredFieldValidator
requiredPasswordValidator;
protected System.Web.UI.WebControls.CustomValidator invalidPasswordValidator;
protected System.Web.UI.WebControls.TextBox passwordTxtBox;
protected System.Web.UI.WebControls.Label promptlabel;
protected System.Web.UI.WebControls.DropDownList authourisedusernameList;
protected System.Web.UI.WebControls.Label passwordLabel;
protected System.Web.UI.WebControls.TextBox passwordTextBox;

//Page Loader
//Reading the list of user names from authoriseduser table
private void Page_Load(object sender, System.EventArgs e)
{
if ( !IsPostBack )
{
//open Database
oleDbConnection1.Open();
//execute query
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader(); ' line of error
// add first authorisedusername to the list
while ( dataReader.Read() )
authorisedusernameList.Items.Add( dataReader.GetString( 0 ) );

// close database connection
oleDbConnection1.Close();
}
// Put user code to initialize the page here
} // end of Page_Load
private void invalidPasswordValidator_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args )
{
//open database connection
oleDbConnection1.Open();

oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM AuthorisedUsers
WHERE LoginName = '" +
Request.Form[ "authorisedusernameList" ].ToString() + "'";
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();
dataReader.Read();
//if password is correct create authentication ticketfor user
if ( args.Value == dataReader.GetString( 1 ) )
{
FormsAuthentication.SetAuthCookie(
Request.Form[ "authorisedusernameList" ], false);
Session.Add( "name", Request.Form[ "authorisedusernameList" ].ToString());
Response.Redirect( "LoggedCall.apsx" );
}
else
args.IsValid=false;
//close database connection
oleDbConnection1.Close();
}// end method invalidPasswordValidator_ServerValidate
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = @"Integrated Security=SSPI;Packet
Size=4096;Data Source=""ERYCKOP-002"";Tag with column collation when
possible=False;Initial Catalog=Project;Use Procedure for Prepare=1;Auto
Translate=True;Persist Security
Info=False;Provider=""SQLOLEDB.1"";Workstation ID=""ERYCKOP-002"";Use
Encryption for Data=False";
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion


}//end class login
}
----end of code------

any help is much needed.
Thank you
 
G

Guest

Hi Deepak,

I had a select statement for the oleDbAdapter in the function
InValiPasswordValidator_ServerValidate(). I aslo followed your suggestion and
put this code
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM AuthorisedUsers
WHERE LoginName = '" +Request.Form [ "authorisedusernameList" ].ToString()
+ "'";

before the line
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();

Now I am getting the same error on the line
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM
I know I am new to .NET environment but i do not see why it should give
error on an which has been declared and initialised.
your help is much appreciated.

Thanks.
Deepak said:
In your statement
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();

the adapter does not have a selectCommand at this point.

You will have to do:
oleDbDataAdapter1.SelectCommand = <some sql query>


Regards,

Deepak
[I Code, therefore I am]


kojosmooth said:
hello all,
I am new to C# and ASP, I am trying to build and applicationwith a login in
page. I followed an example from a book to create his page but I am havin
problem when i run the program.
I know there has been a thread like this in this forum but the suggestion I
have tried does not correct this problem. please have a look at the code belo
and help me.need help urgently. you help is much appreciated.
When i run the run I get this error in the browser, Object reference not set
to an instance of an object"
The error is on the line coloured red - dataReader =
oleDbDataAdapter1.SelectCommand.ExecuteReader();

'------code from program---------

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.OleDb;
namespace WebsupportProject
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
/// allow authorised users to login
public class Login : System.Web.UI.Page
{
protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
protected System.Data.OleDb.OleDbConnection oleDbConnection1;
protected System.Data.OleDb.OleDbDataReader dataReader;
//web form labels
protected System.Web.UI.WebControls.Label lbpassword;
protected System.Web.UI.WebControls.Label lbauthorisedusername;
protected System.Web.UI.WebControls.Label lbprompt;
protected System.Web.UI.WebControls.DropDownList authorisedusernameList;
protected System.Web.UI.WebControls.Button submitButton;
protected System.Web.UI.WebControls.RequiredFieldValidator
requiredPasswordValidator;
protected System.Web.UI.WebControls.CustomValidator invalidPasswordValidator;
protected System.Web.UI.WebControls.TextBox passwordTxtBox;
protected System.Web.UI.WebControls.Label promptlabel;
protected System.Web.UI.WebControls.DropDownList authourisedusernameList;
protected System.Web.UI.WebControls.Label passwordLabel;
protected System.Web.UI.WebControls.TextBox passwordTextBox;

//Page Loader
//Reading the list of user names from authoriseduser table
private void Page_Load(object sender, System.EventArgs e)
{
if ( !IsPostBack )
{
//open Database
oleDbConnection1.Open();
//execute query
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader(); ' line of error
// add first authorisedusername to the list
while ( dataReader.Read() )
authorisedusernameList.Items.Add( dataReader.GetString( 0 ) );

// close database connection
oleDbConnection1.Close();
}
// Put user code to initialize the page here
} // end of Page_Load
private void invalidPasswordValidator_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args )
{
//open database connection
oleDbConnection1.Open();

oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM AuthorisedUsers
WHERE LoginName = '" +
Request.Form[ "authorisedusernameList" ].ToString() + "'";
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();
dataReader.Read();
//if password is correct create authentication ticketfor user
if ( args.Value == dataReader.GetString( 1 ) )
{
FormsAuthentication.SetAuthCookie(
Request.Form[ "authorisedusernameList" ], false);
Session.Add( "name", Request.Form[ "authorisedusernameList" ].ToString());
Response.Redirect( "LoggedCall.apsx" );
}
else
args.IsValid=false;
//close database connection
oleDbConnection1.Close();
}// end method invalidPasswordValidator_ServerValidate
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = @"Integrated Security=SSPI;Packet
Size=4096;Data Source=""ERYCKOP-002"";Tag with column collation when
possible=False;Initial Catalog=Project;Use Procedure for Prepare=1;Auto
Translate=True;Persist Security
Info=False;Provider=""SQLOLEDB.1"";Workstation ID=""ERYCKOP-002"";Use
Encryption for Data=False";
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion


}//end class login
}
----end of code------

any help is much needed.
Thank you
 
S

Sahil Malik

Kojo,

Deepak's suggestion is correct with a slight twist -

The "InValiPasswordValidator_ServerValidate" hasn't been called until you
have reached the line of error. (Which as the logic reads, is called at
!Page.IsPostBack - i.e. the first time the page is shown - without the
postback that is).

So, Even though you did specify the DataAdapter in InitializeComponent, the
"SelectCommand" object hasn't been definied.

So .. in addition to specifiying the SelectCommand, you will have to first
create a new SqlCommand and associate it with the DataReader. .. the code
will be similar to as below.

SqlCommand selectcmd = new SqlCommand ;
selectcmd.Connection = oleDbConnection1 ;
oleDbDataAdapter1.SelectCommand = selectcmd.

You might want to put this code in InitializeComponent.


This should solve the issue - as an additional tip (you might already know
this, but here goes anyway) you can go to the problem line, hit F9, and
create a breakpoint and then press F5, the code execution will stop at the
breakpoint and allow to examine **exactly** which object is null at that
point.

Hope this helped.


- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik




kojosmooth said:
Hi Deepak,

I had a select statement for the oleDbAdapter in the function
InValiPasswordValidator_ServerValidate(). I aslo followed your suggestion
and
put this code
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM
AuthorisedUsers
WHERE LoginName = '" +Request.Form [
"authorisedusernameList" ].ToString()
+ "'";

before the line
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();

Now I am getting the same error on the line
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM
I know I am new to .NET environment but i do not see why it should give
error on an which has been declared and initialised.
your help is much appreciated.

Thanks.
Deepak said:
In your statement
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();

the adapter does not have a selectCommand at this point.

You will have to do:
oleDbDataAdapter1.SelectCommand = <some sql query>


Regards,

Deepak
[I Code, therefore I am]


kojosmooth said:
hello all,
I am new to C# and ASP, I am trying to build and applicationwith a
login in
page. I followed an example from a book to create his page but I am
havin
problem when i run the program.
I know there has been a thread like this in this forum but the
suggestion I
have tried does not correct this problem. please have a look at the
code belo
and help me.need help urgently. you help is much appreciated.
When i run the run I get this error in the browser, Object reference
not set
to an instance of an object"
The error is on the line coloured red - dataReader =
oleDbDataAdapter1.SelectCommand.ExecuteReader();

'------code from program---------

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.OleDb;
namespace WebsupportProject
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
/// allow authorised users to login
public class Login : System.Web.UI.Page
{
protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
protected System.Data.OleDb.OleDbConnection oleDbConnection1;
protected System.Data.OleDb.OleDbDataReader dataReader;
//web form labels
protected System.Web.UI.WebControls.Label lbpassword;
protected System.Web.UI.WebControls.Label lbauthorisedusername;
protected System.Web.UI.WebControls.Label lbprompt;
protected System.Web.UI.WebControls.DropDownList
authorisedusernameList;
protected System.Web.UI.WebControls.Button submitButton;
protected System.Web.UI.WebControls.RequiredFieldValidator
requiredPasswordValidator;
protected System.Web.UI.WebControls.CustomValidator
invalidPasswordValidator;
protected System.Web.UI.WebControls.TextBox passwordTxtBox;
protected System.Web.UI.WebControls.Label promptlabel;
protected System.Web.UI.WebControls.DropDownList
authourisedusernameList;
protected System.Web.UI.WebControls.Label passwordLabel;
protected System.Web.UI.WebControls.TextBox passwordTextBox;

//Page Loader
//Reading the list of user names from authoriseduser table
private void Page_Load(object sender, System.EventArgs e)
{
if ( !IsPostBack )
{
//open Database
oleDbConnection1.Open();
//execute query
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader(); ' line of
error
// add first authorisedusername to the list
while ( dataReader.Read() )
authorisedusernameList.Items.Add( dataReader.GetString( 0 ) );

// close database connection
oleDbConnection1.Close();
}
// Put user code to initialize the page here
} // end of Page_Load
private void invalidPasswordValidator_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args )
{
//open database connection
oleDbConnection1.Open();

oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM
AuthorisedUsers
WHERE LoginName = '" +
Request.Form[ "authorisedusernameList" ].ToString() + "'";
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();
dataReader.Read();
//if password is correct create authentication ticketfor user
if ( args.Value == dataReader.GetString( 1 ) )
{
FormsAuthentication.SetAuthCookie(
Request.Form[ "authorisedusernameList" ], false);
Session.Add( "name", Request.Form[
"authorisedusernameList" ].ToString());
Response.Redirect( "LoggedCall.apsx" );
}
else
args.IsValid=false;
//close database connection
oleDbConnection1.Close();
}// end method invalidPasswordValidator_ServerValidate
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = @"Integrated
Security=SSPI;Packet
Size=4096;Data Source=""ERYCKOP-002"";Tag with column collation when
possible=False;Initial Catalog=Project;Use Procedure for Prepare=1;Auto
Translate=True;Persist Security
Info=False;Provider=""SQLOLEDB.1"";Workstation ID=""ERYCKOP-002"";Use
Encryption for Data=False";
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion


}//end class login
}
----end of code------

any help is much needed.
Thank you
 
G

Guest

Hi All,
Thanks for the quick response which has been of immense help. it has help me
to correct some other error relating initialising authoriseduserslist
variable.

However this has brought up another error I just can not figure out what to
do to correct it. I have updated my code and is listed below,

I am getting this error
''----------------------Error-------------------------
The data value could not be converted for reasons other than sign mismatch
or data overflow. For example, the data was corrupted in the data store but
the row was still retrievable.
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.InvalidCastException: The data value could not be
converted for reasons other than sign mismatch or data overflow. For example,
the data was corrupted in the data store but the row was still retrievable.

Source Error:

Line 56: authorisedusernameList.Items.Add( dataReader.GetString( 0 ) );

Source File: c:\inetpub\wwwroot\websupportproject\login.aspx.cs Line: 56

Stack Trace:
[InvalidCastException: The data value could not be converted for reasons
other than sign mismatch or data overflow. For example, the data was
corrupted in the data store but the row was still retrievable.]
System.Data.OleDb.DBBindings.get_ValueString()
System.Data.OleDb.OleDbDataReader.GetString(Int32 ordinal)
WebsupportProject.Login.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\websupportproject\login.aspx.cs:56
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
'---------------end of error------------------------------

this is the updated code.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.OleDb;

namespace WebsupportProject
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
/// allow authorised users to login
public class Login : System.Web.UI.Page
{
protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
protected System.Data.OleDb.OleDbConnection oleDbConnection1;
protected System.Data.OleDb.OleDbDataReader dataReader;
//protected System.Data.SqlClient.SqlCommand selectcmd;

//web form labels
protected System.Web.UI.WebControls.Label lbpassword;
protected System.Web.UI.WebControls.Label lbauthorisedusername;
protected System.Web.UI.WebControls.Label lbprompt;

protected System.Web.UI.WebControls.DropDownList authorisedusernameList;
protected System.Web.UI.WebControls.Button submitButton;
protected System.Web.UI.WebControls.RequiredFieldValidator
requiredPasswordValidator;
protected System.Web.UI.WebControls.CustomValidator
invalidPasswordValidator;
protected System.Web.UI.WebControls.TextBox passwordTxtBox;
protected System.Web.UI.WebControls.Label promptlabel;
protected System.Web.UI.WebControls.DropDownList authourisedusernameList;
protected System.Web.UI.WebControls.Label passwordLabel;
protected System.Web.UI.WebControls.TextBox passwordTextBox;


private void Page_Load(object sender, System.EventArgs e)
{
if ( !IsPostBack )
{
//open Database
oleDbConnection1.Open();
//execute query
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();
while ( dataReader.Read() )
authorisedusernameList.Items.Add( dataReader.GetString( 0 ) );

// close database connection
oleDbConnection1.Close();
}
// Put user code to initialize the page here
} // end of Page_Load


private void invalidPasswordValidator_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args )
{
//open database connection
oleDbConnection1.Open();

oleDbDataAdapter1.SelectCommand.CommandText = "SELECT
AuthorisedUsers.LoginName, AuthorisedUsers.Password FROM AuthorisedUsers
WHERE LoginName = '" +
Request.Form[ "authorisedusernameList" ].ToString() + "'";
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();

dataReader.Read();

//if password is correct create authentication ticketfor user
if ( args.Value == dataReader.GetString( 1 ) )
{
FormsAuthentication.SetAuthCookie(
Request.Form[ "authorisedusernameList" ], false);
Session.Add( "name", Request.Form[ "authorisedusernameList" ].ToString());
Response.Redirect( "ContentPage.apsx" );
}
else
args.IsValid=false;

//close database connection
oleDbConnection1.Close();
}// end method invalidPasswordValidator_ServerValidate

//Page Loader
//Reading the list of user names from authoriseduser table




#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand ();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.authorisedusernameList = new System.Web.UI.WebControls.DropDownList();
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = @"Integrated
Security=SSPI;Packet Size=4096;Data Source=""ERYCKOP-002"";Tag with column
collation when possible=False;Initial Catalog=Project;Use Procedure for
Prepare=1;Auto Translate=True;Persist Security
Info=False;Provider=""SQLOLEDB.1"";Workstation ID=""ERYCKOP-002"";Use
Encryption for Data=False";
this.Load += new System.EventHandler(this.Page_Load);
//this.selectcmd = new System.Data.SqlClient.SqlCommand();
oleDbSelectCommand1.Connection = oleDbConnection1;
// String oleDbSelectCommand1.CommandText;

oleDbDataAdapter1.SelectCommand = oleDbSelectCommand1;
oleDbSelectCommand1.CommandText = "SELECT * FROM AuthorisedUsers";
//oleDbSelectCommand1.CommandText = "SELECT * FROM AuthorisedUsers WHERE
LoginName = '" +
// Request.Form[ "authorisedusernameList" ].ToString() + "'";



//selectcmd.Connection = oleDbConnection1;
//oleDbDataAdapter1.SelectCommand = selectcmd;


}
#endregion




}//end class login
}
' --------end of code------

Thank you for your help so far.



Sahil Malik said:
Kojo,

Deepak's suggestion is correct with a slight twist -

The "InValiPasswordValidator_ServerValidate" hasn't been called until you
have reached the line of error. (Which as the logic reads, is called at
!Page.IsPostBack - i.e. the first time the page is shown - without the
postback that is).

So, Even though you did specify the DataAdapter in InitializeComponent, the
"SelectCommand" object hasn't been definied.

So .. in addition to specifiying the SelectCommand, you will have to first
create a new SqlCommand and associate it with the DataReader. .. the code
will be similar to as below.

SqlCommand selectcmd = new SqlCommand ;
selectcmd.Connection = oleDbConnection1 ;
oleDbDataAdapter1.SelectCommand = selectcmd.

You might want to put this code in InitializeComponent.


This should solve the issue - as an additional tip (you might already know
this, but here goes anyway) you can go to the problem line, hit F9, and
create a breakpoint and then press F5, the code execution will stop at the
breakpoint and allow to examine **exactly** which object is null at that
point.

Hope this helped.


- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik




kojosmooth said:
Hi Deepak,

I had a select statement for the oleDbAdapter in the function
InValiPasswordValidator_ServerValidate(). I aslo followed your suggestion
and
put this code
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM
AuthorisedUsers
WHERE LoginName = '" +Request.Form [
"authorisedusernameList" ].ToString()
+ "'";

before the line
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();

Now I am getting the same error on the line
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM
I know I am new to .NET environment but i do not see why it should give
error on an which has been declared and initialised.
your help is much appreciated.

Thanks.
Deepak said:
In your statement
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();

the adapter does not have a selectCommand at this point.

You will have to do:
oleDbDataAdapter1.SelectCommand = <some sql query>


Regards,

Deepak
[I Code, therefore I am]


:

hello all,
I am new to C# and ASP, I am trying to build and applicationwith a
login in
page. I followed an example from a book to create his page but I am
havin
problem when i run the program.
I know there has been a thread like this in this forum but the
suggestion I
have tried does not correct this problem. please have a look at the
code belo
and help me.need help urgently. you help is much appreciated.
When i run the run I get this error in the browser, Object reference
not set
to an instance of an object"
The error is on the line coloured red - dataReader =
oleDbDataAdapter1.SelectCommand.ExecuteReader();

'------code from program---------

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.OleDb;
namespace WebsupportProject
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
/// allow authorised users to login
public class Login : System.Web.UI.Page
{
protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
protected System.Data.OleDb.OleDbConnection oleDbConnection1;
protected System.Data.OleDb.OleDbDataReader dataReader;
//web form labels
protected System.Web.UI.WebControls.Label lbpassword;
protected System.Web.UI.WebControls.Label lbauthorisedusername;
protected System.Web.UI.WebControls.Label lbprompt;
protected System.Web.UI.WebControls.DropDownList
authorisedusernameList;
protected System.Web.UI.WebControls.Button submitButton;
protected System.Web.UI.WebControls.RequiredFieldValidator
requiredPasswordValidator;
protected System.Web.UI.WebControls.CustomValidator
invalidPasswordValidator;
protected System.Web.UI.WebControls.TextBox passwordTxtBox;
protected System.Web.UI.WebControls.Label promptlabel;
protected System.Web.UI.WebControls.DropDownList
authourisedusernameList;
protected System.Web.UI.WebControls.Label passwordLabel;
protected System.Web.UI.WebControls.TextBox passwordTextBox;

//Page Loader
//Reading the list of user names from authoriseduser table
private void Page_Load(object sender, System.EventArgs e)
{
if ( !IsPostBack )
{
//open Database
oleDbConnection1.Open();
//execute query
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader(); ' line of
error
// add first authorisedusername to the list
while ( dataReader.Read() )
authorisedusernameList.Items.Add( dataReader.GetString( 0 ) );

// close database connection
oleDbConnection1.Close();
}
// Put user code to initialize the page here
} // end of Page_Load
private void invalidPasswordValidator_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args )
{
//open database connection
oleDbConnection1.Open();

oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM
AuthorisedUsers
WHERE LoginName = '" +
Request.Form[ "authorisedusernameList" ].ToString() + "'";
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();
dataReader.Read();
//if password is correct create authentication ticketfor user
if ( args.Value == dataReader.GetString( 1 ) )
{
FormsAuthentication.SetAuthCookie(
Request.Form[ "authorisedusernameList" ], false);
Session.Add( "name", Request.Form[
"authorisedusernameList" ].ToString());
Response.Redirect( "LoggedCall.apsx" );
}
else
args.IsValid=false;
//close database connection
oleDbConnection1.Close();
}// end method invalidPasswordValidator_ServerValidate
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = @"Integrated
Security=SSPI;Packet
Size=4096;Data Source=""ERYCKOP-002"";Tag with column collation when
possible=False;Initial Catalog=Project;Use Procedure for Prepare=1;Auto
Translate=True;Persist Security
Info=False;Provider=""SQLOLEDB.1"";Workstation ID=""ERYCKOP-002"";Use
Encryption for Data=False";
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion


}//end class login
}
----end of code------

any help is much needed.
Thank you
 
S

Sahil Malik

Kojo,

Hard to say without setting a breakpoint at the offending line and checking
the values - but one of the possible fixes could be to change this line -

authorisedusernameList.Items.Add( dataReader.GetString( 0 ) );

to

authorisedusernameList.Items.Add( dataReader.GetString( 0 ).ToString() );

or

authorisedusernameList.Items.Add( (string) dataReader.GetString( 0 ) );

BTW, what is the datatype at column #0?

Again - the above might not be why you are getting this error, but it is
hard to debug without your setting a breakpoint and examining the value of
dataReader.GetString(0).

Another reason could be - you might not be getting any rows back out of your
query.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
http://blogs.apress.com/authors.php?author=Sahil Malik




kojosmooth said:
Hi All,
Thanks for the quick response which has been of immense help. it has help me
to correct some other error relating initialising authoriseduserslist
variable.

However this has brought up another error I just can not figure out what to
do to correct it. I have updated my code and is listed below,

I am getting this error
''----------------------Error-------------------------
The data value could not be converted for reasons other than sign mismatch
or data overflow. For example, the data was corrupted in the data store but
the row was still retrievable.
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.InvalidCastException: The data value could not be
converted for reasons other than sign mismatch or data overflow. For example,
the data was corrupted in the data store but the row was still retrievable.

Source Error:

Line 56: authorisedusernameList.Items.Add( dataReader.GetString( 0 ) );

Source File: c:\inetpub\wwwroot\websupportproject\login.aspx.cs Line: 56

Stack Trace:
[InvalidCastException: The data value could not be converted for reasons
other than sign mismatch or data overflow. For example, the data was
corrupted in the data store but the row was still retrievable.]
System.Data.OleDb.DBBindings.get_ValueString()
System.Data.OleDb.OleDbDataReader.GetString(Int32 ordinal)
WebsupportProject.Login.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\websupportproject\login.aspx.cs:56
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
'---------------end of error------------------------------

this is the updated code.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.OleDb;

namespace WebsupportProject
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
/// allow authorised users to login
public class Login : System.Web.UI.Page
{
protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
protected System.Data.OleDb.OleDbConnection oleDbConnection1;
protected System.Data.OleDb.OleDbDataReader dataReader;
//protected System.Data.SqlClient.SqlCommand selectcmd;

//web form labels
protected System.Web.UI.WebControls.Label lbpassword;
protected System.Web.UI.WebControls.Label lbauthorisedusername;
protected System.Web.UI.WebControls.Label lbprompt;

protected System.Web.UI.WebControls.DropDownList authorisedusernameList;
protected System.Web.UI.WebControls.Button submitButton;
protected System.Web.UI.WebControls.RequiredFieldValidator
requiredPasswordValidator;
protected System.Web.UI.WebControls.CustomValidator
invalidPasswordValidator;
protected System.Web.UI.WebControls.TextBox passwordTxtBox;
protected System.Web.UI.WebControls.Label promptlabel;
protected System.Web.UI.WebControls.DropDownList authourisedusernameList;
protected System.Web.UI.WebControls.Label passwordLabel;
protected System.Web.UI.WebControls.TextBox passwordTextBox;


private void Page_Load(object sender, System.EventArgs e)
{
if ( !IsPostBack )
{
//open Database
oleDbConnection1.Open();
//execute query
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();
while ( dataReader.Read() )
authorisedusernameList.Items.Add( dataReader.GetString( 0 ) );

// close database connection
oleDbConnection1.Close();
}
// Put user code to initialize the page here
} // end of Page_Load


private void invalidPasswordValidator_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args )
{
//open database connection
oleDbConnection1.Open();

oleDbDataAdapter1.SelectCommand.CommandText = "SELECT
AuthorisedUsers.LoginName, AuthorisedUsers.Password FROM AuthorisedUsers
WHERE LoginName = '" +
Request.Form[ "authorisedusernameList" ].ToString() + "'";
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();

dataReader.Read();

//if password is correct create authentication ticketfor user
if ( args.Value == dataReader.GetString( 1 ) )
{
FormsAuthentication.SetAuthCookie(
Request.Form[ "authorisedusernameList" ], false);
Session.Add( "name", Request.Form[ "authorisedusernameList" ].ToString());
Response.Redirect( "ContentPage.apsx" );
}
else
args.IsValid=false;

//close database connection
oleDbConnection1.Close();
}// end method invalidPasswordValidator_ServerValidate

//Page Loader
//Reading the list of user names from authoriseduser table




#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand ();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
this.authorisedusernameList = new System.Web.UI.WebControls.DropDownList();
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = @"Integrated
Security=SSPI;Packet Size=4096;Data Source=""ERYCKOP-002"";Tag with column
collation when possible=False;Initial Catalog=Project;Use Procedure for
Prepare=1;Auto Translate=True;Persist Security
Info=False;Provider=""SQLOLEDB.1"";Workstation ID=""ERYCKOP-002"";Use
Encryption for Data=False";
this.Load += new System.EventHandler(this.Page_Load);
//this.selectcmd = new System.Data.SqlClient.SqlCommand();
oleDbSelectCommand1.Connection = oleDbConnection1;
// String oleDbSelectCommand1.CommandText;

oleDbDataAdapter1.SelectCommand = oleDbSelectCommand1;
oleDbSelectCommand1.CommandText = "SELECT * FROM AuthorisedUsers";
//oleDbSelectCommand1.CommandText = "SELECT * FROM AuthorisedUsers WHERE
LoginName = '" +
// Request.Form[ "authorisedusernameList" ].ToString() + "'";



//selectcmd.Connection = oleDbConnection1;
//oleDbDataAdapter1.SelectCommand = selectcmd;


}
#endregion




}//end class login
}
' --------end of code------

Thank you for your help so far.



Sahil Malik said:
Kojo,

Deepak's suggestion is correct with a slight twist -

The "InValiPasswordValidator_ServerValidate" hasn't been called until you
have reached the line of error. (Which as the logic reads, is called at
!Page.IsPostBack - i.e. the first time the page is shown - without the
postback that is).

So, Even though you did specify the DataAdapter in InitializeComponent, the
"SelectCommand" object hasn't been definied.

So .. in addition to specifiying the SelectCommand, you will have to first
create a new SqlCommand and associate it with the DataReader. .. the code
will be similar to as below.

SqlCommand selectcmd = new SqlCommand ;
selectcmd.Connection = oleDbConnection1 ;
oleDbDataAdapter1.SelectCommand = selectcmd.

You might want to put this code in InitializeComponent.


This should solve the issue - as an additional tip (you might already know
this, but here goes anyway) you can go to the problem line, hit F9, and
create a breakpoint and then press F5, the code execution will stop at the
breakpoint and allow to examine **exactly** which object is null at that
point.

Hope this helped.


- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik




kojosmooth said:
Hi Deepak,

I had a select statement for the oleDbAdapter in the function
InValiPasswordValidator_ServerValidate(). I aslo followed your suggestion
and
put this code
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM
AuthorisedUsers
WHERE LoginName = '" +Request.Form [
"authorisedusernameList" ].ToString()
+ "'";

before the line
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();

Now I am getting the same error on the line
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM
I know I am new to .NET environment but i do not see why it should give
error on an which has been declared and initialised.
your help is much appreciated.

Thanks.
:

In your statement
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();

the adapter does not have a selectCommand at this point.

You will have to do:
oleDbDataAdapter1.SelectCommand = <some sql query>


Regards,

Deepak
[I Code, therefore I am]


:

hello all,
I am new to C# and ASP, I am trying to build and applicationwith a
login in
page. I followed an example from a book to create his page but I am
havin
problem when i run the program.
I know there has been a thread like this in this forum but the
suggestion I
have tried does not correct this problem. please have a look at the
code belo
and help me.need help urgently. you help is much appreciated.
When i run the run I get this error in the browser, Object reference
not set
to an instance of an object"
The error is on the line coloured red - dataReader =
oleDbDataAdapter1.SelectCommand.ExecuteReader();

'------code from program---------

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Data.OleDb;
namespace WebsupportProject
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
/// allow authorised users to login
public class Login : System.Web.UI.Page
{
protected System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
protected System.Data.OleDb.OleDbCommand oleDbSelectCommand1;
protected System.Data.OleDb.OleDbCommand oleDbInsertCommand1;
protected System.Data.OleDb.OleDbCommand oleDbUpdateCommand1;
protected System.Data.OleDb.OleDbCommand oleDbDeleteCommand1;
protected System.Data.OleDb.OleDbConnection oleDbConnection1;
protected System.Data.OleDb.OleDbDataReader dataReader;
//web form labels
protected System.Web.UI.WebControls.Label lbpassword;
protected System.Web.UI.WebControls.Label lbauthorisedusername;
protected System.Web.UI.WebControls.Label lbprompt;
protected System.Web.UI.WebControls.DropDownList
authorisedusernameList;
protected System.Web.UI.WebControls.Button submitButton;
protected System.Web.UI.WebControls.RequiredFieldValidator
requiredPasswordValidator;
protected System.Web.UI.WebControls.CustomValidator
invalidPasswordValidator;
protected System.Web.UI.WebControls.TextBox passwordTxtBox;
protected System.Web.UI.WebControls.Label promptlabel;
protected System.Web.UI.WebControls.DropDownList
authourisedusernameList;
protected System.Web.UI.WebControls.Label passwordLabel;
protected System.Web.UI.WebControls.TextBox passwordTextBox;

//Page Loader
//Reading the list of user names from authoriseduser table
private void Page_Load(object sender, System.EventArgs e)
{
if ( !IsPostBack )
{
//open Database
oleDbConnection1.Open();
//execute query
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader(); ' line of
error
// add first authorisedusername to the list
while ( dataReader.Read() )
authorisedusernameList.Items.Add( dataReader.GetString( 0 ) );

// close database connection
oleDbConnection1.Close();
}
// Put user code to initialize the page here
} // end of Page_Load
private void invalidPasswordValidator_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args )
{
//open database connection
oleDbConnection1.Open();

oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM
AuthorisedUsers
WHERE LoginName = '" +
Request.Form[ "authorisedusernameList" ].ToString() + "'";
dataReader = oleDbDataAdapter1.SelectCommand.ExecuteReader();
dataReader.Read();
//if password is correct create authentication ticketfor user
if ( args.Value == dataReader.GetString( 1 ) )
{
FormsAuthentication.SetAuthCookie(
Request.Form[ "authorisedusernameList" ], false);
Session.Add( "name", Request.Form[
"authorisedusernameList" ].ToString());
Response.Redirect( "LoggedCall.apsx" );
}
else
args.IsValid=false;
//close database connection
oleDbConnection1.Close();
}// end method invalidPasswordValidator_ServerValidate
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.oleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter();
this.oleDbSelectCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbInsertCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbUpdateCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbDeleteCommand1 = new System.Data.OleDb.OleDbCommand();
this.oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
//
// oleDbConnection1
//
this.oleDbConnection1.ConnectionString = @"Integrated
Security=SSPI;Packet
Size=4096;Data Source=""ERYCKOP-002"";Tag with column collation when
possible=False;Initial Catalog=Project;Use Procedure for Prepare=1;Auto
Translate=True;Persist Security
Info=False;Provider=""SQLOLEDB.1"";Workstation ID=""ERYCKOP-002"";Use
Encryption for Data=False";
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion


}//end class login
}
----end of code------

any help is much needed.
Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top