Is your method returning a
DataTable
object?
If no, your whole logic may got fail.
If yes, you haven't put any check on wheather that datatable really contains a row or not. So, following line of code will raise error when there is an empty datatable.
pp[i] += con.QueryEx().Rows[i][j].ToString();
pp[0] += con.QueryEx().Rows[0][0].ToString();
It pass previos steps as the rows and columns count is 0 but will throw error in the above line.
Try putting some validation like-
int p = con.QueryEx().Rows.Count;
int b = con.QueryEx().Columns.Count;
if(p>0)
{
for (int i = 0; i < p; i++)
{
}
}
Hope, it helps :)