Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object reference not set to an instance of an object

Status
Not open for further replies.

z07924

IS-IT--Management
Feb 18, 2002
122
0
0
GB
private void dlUserName_SelectedIndexChanged(object sender, System.EventArgs e)
{
lblOpDesc.Text = "" + Session["gUserID"] + "";
string varUserName = dlUserName.SelectedItem.Value;

string strDSNUserID = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\\\Paragon\\databases\\Super_6\\Test\\ParaNet\\ParaNet.mdb";

string strSqlUserID = " Select * from AspLoginUserTbl where UserName = '" + varUserName + "' ";

OleDbConnection myConnUserID = new OleDbConnection(strDSNUserID);
OleDbCommand myCmdUserID = new OleDbCommand(strSqlUserID, myConnUserID);
OleDbDataReader drUserID = null;
myConnUserID.Open();
drUserID = myCmdUserID.ExecuteReader();

if( dlAccessType.SelectedItem.Value == "Corporate")
{
lblRegion.Visible=false;
lblDistrict.Visible=false;
}

myConnUserID.Close();
}

When I select item from dlAccessType, first time is working.
When I do the same for the first item in the list,
It is giving error as given below,

"Object reference not set to an instance of an object. "

Line 299:
Line 300:
Line 301: if( dlAccessType.SelectedItem.Value == "Corporate")
Line 302: {
Line 303: lblRegion.Visible=false;


Source File: c:\inetpub\ Line: 301

Looks like dlAccessType.SelectedItem.Value is coming "Null"
value, when I select the item from the list at the second time.
It works good, when I select an item from the list at the first time.

Somehow When I do the same process at the second time, it is giving me an error.

Any help would be really apprecited..

Thanks in Advance.
 
For starters, try changing this:

lblOpDesc.Text = "" + Session"gUserID" + "";

...to this:

lblOpDesc.Text = "" + Session["gUserID"] + "";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top