That isn't going to work:
Your SQL is not valid.
if (cmbPlan.Text == "SID")
{
qry = "SELECT accountname,tableno,refererid,investment,dateofexpiry FROM investers_sid WHERE investeridsid";
}
else if (cmbPlan.Text == "RUC")
{
qry = "SELECT accountname,tableno,refererid,investment,dateofexpiry FROM investers_ruc WHERE investeridruc";
}
else if (cmbPlan.Text == "PS")
{
qry = "SELECT accountname,tableno,refererid,investment,dateofexpiry FROM investers_ps WHERE investeridps";
}
MySqlCommand cmd = new MySqlCommand(qry, con);
MySqlDataReader r = cmd.ExecuteReader();
Cutting your SQL down to just the basics:
SELECT field1 FROM table WHERE field2
Will cause an exception at the SQL, because "field2" is not a valid comparison. You need to compare it against a specific value in order to get it to work. Try using a Parametrised query instead:
if (cmbPlan.Text == "SID")
{
qry = "SELECT accountname,tableno,refererid,investment,dateofexpiry FROM investers_sid WHERE investeridsid=@ID";
}
else if (cmbPlan.Text == "RUC")
{
qry = "SELECT accountname,tableno,refererid,investment,dateofexpiry FROM investers_ruc WHERE investeridruc=@ID";
}
else if (cmbPlan.Text == "PS")
{
qry = "SELECT accountname,tableno,refererid,investment,dateofexpiry FROM investers_ps WHERE investeridps=@ID";
}
MySqlCommand cmd = new MySqlCommand(qry, con);
cmd.Parameters.AddWithValue("@ID", myIdToSearchFor);
MySqlDataReader r = cmd.ExecuteReader();