public static SqlParameter[] get_array_list<T>(ArrayList rows) where T : class { Hashtable sql_add = new Hashtable(); Hashtable sql_update = new Hashtable(); Hashtable sql_delete = new Hashtable(); string zsql = ""; int ka = 0, ku = 0, kd = 0; foreach (Hashtable row in rows) { zsql += " select "; PropertyInfo[] properties = typeof(T).GetProperties(); foreach (PropertyInfo p in properties) { if (row[p.Name] != null) { string zdel_c = Get_Deli(p.PropertyType, row[p.Name].ToString()); zsql += zdel_c + Get_Value(p.PropertyType, row[p.Name].ToString()) + zdel_c + " as [" + p.Name + "] " + ","; } else { zsql += Get_Default_Value(p.PropertyType) + " as [" + p.Name + "] " + ","; } } zsql = zsql.Substring(0, zsql.Length - 1); String state = row["_state"] != null ? row["_state"].ToString() : ""; if (state == "added") { sql_add[ka.ToString()] = zsql; ka++; } if (state == "modified") { sql_update[ku.ToString()] = zsql; ku++; } if (state == "removed" || state == "deleted") { sql_delete[kd.ToString()] = zsql; kd++; } zsql = ""; } SqlParameter[] result = { new SqlParameter("@username" , SqlDbType.NText), new SqlParameter(string.Format("@e{0}_add_array" ,typeof(T).Name), SqlDbType.NText), new SqlParameter(string.Format("@e{0}_update_array" ,typeof(T).Name), SqlDbType.NText), new SqlParameter(string.Format("@e{0}_delete_array" ,typeof(T).Name), SqlDbType.NText) }; zsql = ""; for (int k = 0; k < sql_add.Count; k++) { zsql += sql_add[k.ToString()].ToString(); if (k < sql_add.Count - 1) zsql += "\n union all \n"; } result[1].Value = zsql; zsql = ""; for (int k = 0; k < sql_update.Count; k++) { zsql += sql_update[k.ToString()].ToString(); if (k < sql_update.Count - 1) zsql += "\n union all \n"; } result[2].Value = zsql; zsql = ""; for (int k = 0; k < sql_delete.Count; k++) { zsql += sql_delete[k.ToString()].ToString(); if (k < sql_delete.Count - 1) zsql += "\n union all \n"; } result[3].Value = zsql; return result; }