Results 1 to 6 of 6

Thread: Database Error There is no row at position 2

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    Database Error There is no row at position 2

    Hi, I'm trying to fill some text boxes and a listbox. I have this code:

    VB.NET Code:
    1. DatabaseOperations databaseOperations = new DatabaseOperations();
    2.  
    3. dataTable = new DataTable();
    4. dataTable = databaseOperations.DBNextRecord();
    5.  
    6. FillBoxes("next_record");
    7.  
    8. dataTable = null;
    9. dataTable = new DataTable();
    10. dataTable = databaseOperations.DBAllRecords();
    11.  
    12. // Liste öğesini seç
    13. if (dataTable.Rows.Count >= 1) // Check if the DataTable returns any data from database
    14. {
    15.     if (!DBNull.Value.Equals(dataTable.Rows[currentId]["id"]))
    16.     {
    17.         Lbx_LeftList.SelectedValue = dataTable.Rows[currentId]["id"];
    18.     }
    19. }

    This gives me error: 'There is no row at position 2.' for this line: if (!DBNull.Value.Equals(dataTable.Rows[currentId]["id"])) When I debug, I see that the data table has 2 rows and currentId equals to 2.

    The data table is set like this

    VB.NET Code:
    1. public DataTable DBNextRecord()
    2. {
    3.     connectionString.DataSource = "database.sqlite";
    4.     connectionString.ForeignKeys = true;
    5.     connectionString.JournalMode = SQLiteJournalModeEnum.Wal;
    6.  
    7.     System.Console.WriteLine(connectionString.ToString());
    8.  
    9.     sqlite_conn = new SQLiteConnection(connectionString.ToString());
    10.  
    11.     selectQueryString = @"SELECT
    12.                               S.id,
    13.                               P.txt_press,
    14.                               CA.txt_category,
    15.                               S.txt_repertory_no,
    16.                               T.txt_taken_from,
    17.                               S.txt_revision_date1,
    18.                               S.txt_revision_date2,
    19.                               S.txt_revision_date3,
    20.                               R.txt_region,
    21.                               PR.txt_prepared_by,
    22.                               S.txt_research_date1,
    23.                               S.txt_research_date2,
    24.                               S.txt_research_date3,
    25.                               SP.txt_source_by,
    26.                               M.txt_measure,
    27.                               S.txt_time,
    28.                               C.txt_compiled_by,
    29.                               S.txt_compilation_date,
    30.                               N.txt_notation_by,
    31.                               S.txt_mp3_paths,
    32.                               A.txt_artist,
    33.                               S.txt_song_name,
    34.                               S.txt_lyrics,
    35.                               S.image1,S.image2,S.image3,S.image4,S.image5,S.image6,S.image7,
    36.                               S.image8,S.image9, S.image10,S.image11,S.image12,S.image13,S.image14
    37.                           FROM tbl_sheet S
    38.                           LEFT JOIN tbl_category CA
    39.                               ON CA.id = S.int_category_id
    40.                           LEFT JOIN tbl_press P
    41.                               ON P.id = S.int_press_id
    42.                           LEFT JOIN tbl_taken_from T
    43.                               ON T.id = S.int_taken_from_id
    44.                           LEFT JOIN tbl_prepared_by PR
    45.                               ON PR.id = S.int_prepared_by_id
    46.                           LEFT JOIN tbl_region R
    47.                               ON R.id = S.int_region_id
    48.                           LEFT JOIN tbl_source_by SP
    49.                               ON SP.id = S.int_source_by_id
    50.                           LEFT JOIN tbl_measure M
    51.                               ON M.id = S.int_measure_id
    52.                           LEFT JOIN tbl_compiled_by C
    53.                               ON C.id = S.int_compiled_by_id
    54.                           LEFT JOIN tbl_notation_by N
    55.                               ON N.id = S.int_notation_by_id
    56.                           LEFT JOIN tbl_artist A
    57.                               ON A.id = S.int_artist_id;";
    58.  
    59.     sqlite_conn.Open();
    60.  
    61.     sqliteDataAdapter = new SQLiteDataAdapter(selectQueryString, sqlite_conn.ConnectionString);
    62.     // sqliteCommandBuilder = new SQLiteCommandBuilder(sqliteDataAdapter);
    63.  
    64.     dataTable = new DataTable();
    65.     sqliteDataAdapter.Fill(dataTable);
    66.  
    67.     sqlite_conn.Close();
    68.     sqliteDataAdapter.Dispose();
    69.  
    70.     return dataTable;
    71. }

    How can I fix this?
    Last edited by nikel; Jun 24th, 2018 at 03:26 PM. Reason: I corrected code
    I'm not a man of too many faces
    The mask I wear is one

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width