Question

I am trying to design a mini project of a quiz application using resource bundle. I get an error of There is no row at position 0 when I insert the following if condition. Where I am catching the string from combobox in variable X.

SampleResourceBundle.Loginpage l = new SampleResourceBundle.Loginpage();
if(l.x.Equals("mr_IN"))
   sql = "select * from quesans where qid>48";
else if (l.x.Equals("en_US"))
   sql = "select * from quesans where qid<48";

The error is given in the following statement in the method from the next form:

textBox1.Text = ds.Tables["QA"].Rows[recno].ItemArray[2].ToString();

But if I remove the if statement the code executes perfectly fine.

Was it helpful?

Solution

There are no rows in ds.Tables["QA"].

You need to check if there is a row you want to read before attempting it:

if (recno < ds.Tables["QA"].Rows.Count)
    textBox1.Text = ds.Tables["QA"].Rows[recno].ItemArray[2].ToString();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top