diff options
author | emkael <emkael@tlen.pl> | 2017-09-30 20:10:22 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2017-09-30 20:10:22 +0200 |
commit | c4c905362ccb9042ac1848938bf51ecaef00576a (patch) | |
tree | 8b937537680f6224340ec8ce9988146119b2f981 | |
parent | 83ceead92009ae29981b54de7e85d91e68673e11 (diff) |
Wrapper for INSERT OleDB queries
-rw-r--r-- | Aktywator/Sql.cs | 26 |
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(); + } } } |