Posted By

sophtwarez on 07/29/06


Tagged

database generics c


Versions (?)

Generics with Databinding


 / Published in: C#
 

URL: http://hobbitwerk.brinkster.net

Methinks this is a bad idea but it is a suggested use of generics from the .NET 2.0 Generics Wrox book

  1. public static Dictionary<X, G> BuildDictionary<X, G>(string db, string keyColumn, string valColumn) {
  2. Dictionary<X, G> myDictionary = new Dictionary<X, G>();
  3. SqlDataReader rd = new SqlCommand().ExecuteReader();
  4. while (rd.Read()) {
  5. myDictionary.Add((X)rd[keyColumn], (G)rd[valColumn]); // ? good idea?
  6. }
  7. rd.Close();
  8. return myDictionary;
  9. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: ixia on February 7, 2008

The calling code needs to know what datatype the two columns returned are... This would be ok in a data access layer, but personally I would not even do it there.

You need to login to post a comment.