Goran Bibic

Goran Bibic

  • 483
  • 2.9k
  • 199.1k

Read data to xamarin mysql

Oct 16 2023 8:22 AM

Can't read data from database
Xamarine
Moble appSelect from database id and name

Two fields
Error

 

System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'

My code

private async void LoadNotes()
       {
           MySqlConnection conn = new MySqlConnection(Constants.connectionString);
           await conn.OpenAsync();

           MySqlCommand cmd = new MySqlCommand(Constants.selectAllQuery, conn);
           cmd.Connection = conn;

           MySqlDataReader rdr = cmd.ExecuteReader();

           if (rdr.HasRows)
           {
               while (rdr.Read())
               {
                   notes.Add(rdr[0]);
                   notes.Add(rdr[1]);
               }
               rdr.Close();

               lstNotes.Adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleExpandableListItem1, notes);
           }
       }

 


Answers (1)