yes, the error line "Object reference not set to an instance of an object" suggests that objects are not instantiated, before they are being used. You can try two things here. Either make your method "CognosGrid()" static so that you can call it directly :
1. public static DataTable CognosGrid()
{
//your code
}
or make an object of the class in which the method resides and then use that object to call that particular method :
protected void btnTest_Click(object sender, EventArgs e)
{
bool found = false;
Class1 objClass= new Class1();
DataTable dataTable = objClass.CognosGrid();
reader = dbCmd.ExecuteReader();
while (reader.Read())
{
if (txtusername.Text == reader.GetString(0) &&
txtpassword.Text == reader.GetString(1))
{
MessageBox.Show("Welldone", " Found");
Response.Redirect("Default.aspx");
found = true;
}
}
if (!found)
{
MessageBox.Show("The account does not exist. Please Register first", "Not Found");
}
}
}
Hope, this would solve your problem. Please provide vote if this was useful.
Anurag
@cheers@