in c# sqlite project, I am compariong two tables wit hthis code: for (int i = 0; i <…
- User
in c# sqlite project, I am compariong two tables wit hthis code:
for (int i = 0; i < originalTable.Rows.Count && tablesAreEqual; i++) { for (int j = 0; j < originalTable.Columns.Count && tablesAreEqual; j++) { if (!originalTable.Rows[i][j].Equals(importedTable.Rows[i][j]) || !(originalTable.Rows[i][j].Equals(DBNull.Value) && importedTable.Rows[i][j].Equals(""))) { tablesAreEqual = false; break; } } }
And these are the values I got from debugging:
codeimportedTable.Rows[i][j] 20180101062818 object {decimal} originalTable.Rows[i][j] 20180101062818 object {decimal} originalTable.Rows[i][j].Equals(DBNull.Value) false bool importedTable.Rows[i][j].Equals("") false bool originalTable.Rows[i][j].Equals(importedTable.Rows[i][j]) true bool !originalTable.Rows[i][j].Equals(importedTable.Rows[i][j]) false booland I don't understand why is going inside the if, if the if condition is false. Why is that?
- Assistant
Based on the values you provided, it seems like the condition inside the if statement is evaluating to
false, which means the code inside the if statement should not execute. However, you mentioned that the code is still going inside the if statement.One possibility for this issue could be related to the evaluation order of the conditions inside the if statement. In C#, the conditions are evaluated from left to right and if any of the conditions evaluate to
false, the subsequent conditions are not evaluated.In your case, the condition is as follows:
csharp!originalTable.Rows[i][j].Equals(importedTable.Rows[i][j]) || !(originalTable.Rows[i][j].Equals(DBNull.Value) && importedTable.Rows[i][j].Equals(""))If the first part of the condition () evaluates to , the second part of the condition () will not be evaluated.
- User
Ok I manage to get it to work but my importer code is not converting my double values correctly. in my CSV I have a datarow with the value '0,33' but it is importing 0 instead. Same with '1113,33', which imports 1113 instead.
my importer code is as follows:
using (SQLiteTransaction transaction = sqliteConn.BeginTransaction()) { using (SQLiteCommand command = new SQLiteCommand(sqliteConn)) { foreach (System.Data.DataRow row in dataTable.Rows) { // Create the INSERT statement System.Text.StringBuilder insertQuery = new System.Text.StringBuilder(); insertQuery.Append($"INSERT INTO {tableName} ");
- Assistant