sql - C# - "An element with the same key was already added" -
i work in asp.net mvc , blocked(surrounded) in model damned error "an element same key added", understand not @ why while have same code different requests in other methods of model.
and not think problem can come request because have used her(it) before in project.
public dictionary<string,string> getdonnee() { dictionary<string, string> list = new dictionary<string, string>(); sqlconnection cn; sqldataadapter da; dataset ds; cn = new sqlconnection(cs_dw); cn.open(); da = new sqldataadapter("select distinct(ltrim(rtrim(cpic))) code, cpic lib [dw].[dbo].[pic_prod_s001] ", cn); ds = new dataset(); da.fill(ds, "code"); list.add("reel", "reel"); foreach (datarow row in ds.tables["code"].rows) { list.add(row["code"].tostring(), row["lib"].tostring()); } cn.close(); return list; }
maybe can test if key in in dictionary
if (!list.containskey(row["code"].tostring())) { list.add(row["code"].tostring(), row["lib"].tostring()); }
Comments
Post a Comment