I use a universal interface-based data provider. Reading data that was created in MS Access is performed without problems. The data that was added through the program, for some reason is not read. To be more precise, they are partially read. For example, you can get the number of rows, but reading the value by the index does not work, as if these lines are not in the database. Method to add a string:
public int AppendRow(string tableName) { IDbCommand cmd = null; IDbDataAdapter ida = null; int result = 0; try { connection.Open(); cmd = connection.CreateCommand(); cmd.CommandText = "INSERT INTO " + tableName + " DEFAULT VALUES"; ida = PrvDataAdapter(); ida.InsertCommand = cmd; result = ida.InsertCommand.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } finally { if (connection.State == ConnectionState.Open) connection.Close(); } cmd.Dispose(); return result; } IDbDataAdapter PrvDataAdapter() { IDbDataAdapter ida = null; switch (_provider) { case Provider.OleDb: ida = new OleDbDataAdapter(); break; case Provider.SqlClient: ida = new SqlDataAdapter(); break; } return ida; } Method for reading integer values (ID field):
public int GetIntValue(string tableName, int indexColumn, int indexRow) { IDbCommand cmd = null; IDataReader idr = null; int value = 0; try { connection.Open(); cmd = connection.CreateCommand(); cmd.CommandText = "SELECT * FROM " + tableName; idr = cmd.ExecuteReader(); DataTable table = new DataTable(); table.Load(idr); DataColumn column = table.Columns[indexColumn]; DataRow row = table.Rows[indexRow]; if (table.Columns[indexColumn].DataType == typeof(int)) value = (int)row[column]; idr.Close(); table.Dispose(); column.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } finally { if (connection.State == ConnectionState.Open) connection.Close(); } cmd.Dispose(); idr.Dispose(); return value; } Apparently, the method of adding a record by default creates incorrect data. The question is, what is not done?
table.Rowsproperty on the index (2) shows the index value (1), although theCountproperty clearly records the total number of rows "3". - vite apprentice