Beispiel #1
0
        public static DataRow Save(this IQuery sql, string TableName, string ViewName, IPair values)
        {
            using (DataTable dt = new DataTable())
            {
                if (!values.ContainsKey("ID"))
                {
                    dt.Columns.Add("ID", typeof(int));
                }

                foreach (KeyValuePair <string, object> hh in values)
                {
                    dt.Columns.Add(hh.Key, (hh.Value.GetType() == typeof(DBNull)) ? typeof(string) : hh.Value.GetType());
                }
                DataRow dr = dt.NewRow();

                foreach (KeyValuePair <string, object> hh in values)
                {
                    if (!values.ContainsKey("ID"))
                    {
                        dr["ID"] = 0;
                    }
                    dr[hh.Key] = hh.Value;
                }
                dt.AcceptChanges();

                using (var g = new QueryMerge(sql as Query)) return(g.Save(TableName, ViewName, dr));
            }
        }