public ADB_Data(DataTable dataTable) { for (int i = 0; i < dataTable.Columns.Count; i++) data_colonsNames.Add(dataTable.Columns[i].ColumnName); for (int i = 0; i < dataTable.Rows.Count; i++) { ADB_Row row = new ADB_Row(dataTable.Rows[i]); data_rows.Add(row); } }
//Modifica una riga parametri: nome tabella, id riga da modificare, nuva riga public ADB_Result Update(string tbName, int id, ADB_Row rowData) { if (rowData.UseColons) { string q = "UPDATE " + tbName + " SET "; for (int i = 0; i < rowData.data_colonsNames.Count; i++) { q += rowData.data_colonsNames[i] + "=" + rowData.data_values[i]; if (i < rowData.data_colonsNames.Count - 1) q += ", "; } q += " WHERE " + Settings.NameColumnId + "=" + id; Query(q, QueryTypes.notquery); return new ADB_Result(changedRecords: 1); } else throw new Exception("Error Update: meaningless parameters"); }
//Inserisce una nuova riga parametri: nome tabella, nuovi riga (Ricordarsi le stringe tra virgolette) public ADB_Result Insert(string tbName, ADB_Row rows) { string q; if (rows.UseColons) { q = "INSERT INTO " + tbName + " ("; for (int i = 0; i< rows.data_colonsNames.Count; i++) { q += rows.data_colonsNames[i]; if (i != rows.data_colonsNames.Count - 1) q += ", "; } q += ") VALUES ("; for (int i = 0; i < rows.data_values.Count; i++) { q += rows.data_values[i]; if (i != rows.data_values.Count - 1) q += ", "; } q += ")"; } else { q = "INSERT INTO " + tbName + " "; q += "VALUES ("; for (int i = 0; i < rows.data_values.Count; i++) { q += rows.data_values[i]; if (i != rows.data_values.Count - 1) q += ", "; } q += ")"; } Query(q, QueryTypes.notquery); return new ADB_Result(addedRecords: rows.data_values.Count); }
public ADB_Row Row(int index, ADB_Row value) { data_rows[index].data_colonsNames = data_colonsNames; data_rows[index] = value; return data_rows[index]; }