summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-09-30 20:10:22 +0200
committeremkael <emkael@tlen.pl>2017-09-30 20:10:22 +0200
commitc4c905362ccb9042ac1848938bf51ecaef00576a (patch)
tree8b937537680f6224340ec8ce9988146119b2f981
parent83ceead92009ae29981b54de7e85d91e68673e11 (diff)
Wrapper for INSERT OleDB queries
-rw-r--r--Aktywator/Sql.cs26
1 files changed, 26 insertions, 0 deletions
diff --git a/Aktywator/Sql.cs b/Aktywator/Sql.cs
index cf0eb38..b3f2104 100644
--- a/Aktywator/Sql.cs
+++ b/Aktywator/Sql.cs
@@ -83,5 +83,31 @@ namespace Aktywator
}
return true;
}
+
+ internal void insert(string table, Dictionary<string, object> columns)
+ {
+ StringBuilder query = new StringBuilder();
+ query.Append("INSERT INTO ");
+ query.Append(table);
+ query.Append(" (");
+ List<string> keys = new List<string>();
+ List<string> parameters = new List<string>();
+ foreach (string key in columns.Keys)
+ {
+ keys.Add("`" + key + "`");
+ parameters.Add("@" + key);
+ }
+ string[] fields = keys.ToArray();
+ query.Append(String.Join(", ", fields));
+ query.Append(") VALUES(");
+ query.Append(String.Join(", ", parameters.ToArray()));
+ query.Append(")");
+ OleDbCommand command = new OleDbCommand(query.ToString(), connection);
+ foreach (KeyValuePair<string, object> column in columns)
+ {
+ command.Parameters.AddWithValue("@" + column.Key, column.Value);
+ }
+ command.ExecuteScalar();
+ }
}
}