Hi, I'm trying to fill some text boxes and a listbox. I have this code:
VB.NET Code:
DatabaseOperations databaseOperations = new DatabaseOperations();
dataTable = new DataTable();
dataTable = databaseOperations.DBNextRecord();
FillBoxes("next_record");
dataTable = null;
dataTable = new DataTable();
dataTable = databaseOperations.DBAllRecords();
// Liste öğesini seç
if (dataTable.Rows.Count >= 1) // Check if the DataTable returns any data from database
{
if (!DBNull.Value.Equals(dataTable.Rows[currentId]["id"]))
{
Lbx_LeftList.SelectedValue = dataTable.Rows[currentId]["id"];
}
}
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:
public DataTable DBNextRecord()
{
connectionString.DataSource = "database.sqlite";
connectionString.ForeignKeys = true;
connectionString.JournalMode = SQLiteJournalModeEnum.Wal;
System.Console.WriteLine(connectionString.ToString());
sqlite_conn = new SQLiteConnection(connectionString.ToString());
selectQueryString = @"SELECT
S.id,
P.txt_press,
CA.txt_category,
S.txt_repertory_no,
T.txt_taken_from,
S.txt_revision_date1,
S.txt_revision_date2,
S.txt_revision_date3,
R.txt_region,
PR.txt_prepared_by,
S.txt_research_date1,
S.txt_research_date2,
S.txt_research_date3,
SP.txt_source_by,
M.txt_measure,
S.txt_time,
C.txt_compiled_by,
S.txt_compilation_date,
N.txt_notation_by,
S.txt_mp3_paths,
A.txt_artist,
S.txt_song_name,
S.txt_lyrics,
S.image1,S.image2,S.image3,S.image4,S.image5,S.image6,S.image7,
S.image8,S.image9, S.image10,S.image11,S.image12,S.image13,S.image14
FROM tbl_sheet S
LEFT JOIN tbl_category CA
ON CA.id = S.int_category_id
LEFT JOIN tbl_press P
ON P.id = S.int_press_id
LEFT JOIN tbl_taken_from T
ON T.id = S.int_taken_from_id
LEFT JOIN tbl_prepared_by PR
ON PR.id = S.int_prepared_by_id
LEFT JOIN tbl_region R
ON R.id = S.int_region_id
LEFT JOIN tbl_source_by SP
ON SP.id = S.int_source_by_id
LEFT JOIN tbl_measure M
ON M.id = S.int_measure_id
LEFT JOIN tbl_compiled_by C
ON C.id = S.int_compiled_by_id
LEFT JOIN tbl_notation_by N
ON N.id = S.int_notation_by_id
LEFT JOIN tbl_artist A
ON A.id = S.int_artist_id;";
sqlite_conn.Open();
sqliteDataAdapter = new SQLiteDataAdapter(selectQueryString, sqlite_conn.ConnectionString);
// sqliteCommandBuilder = new SQLiteCommandBuilder(sqliteDataAdapter);
dataTable = new DataTable();
sqliteDataAdapter.Fill(dataTable);
sqlite_conn.Close();
sqliteDataAdapter.Dispose();
return dataTable;
}
How can I fix this?