hi,
I'm trying to fill a collection using the following 'generic' code:
-----------------
public class baseCollection : System.Collections.CollectionBase
{
protected void Fill(string strSQL, object oTest)
{
SqlConnection Conn = new SqlConnection(Settings.sDBConn);
Conn.Open();
SqlCommand cmdContent = new SqlCommand(strSQL, Conn);
SqlDataReader drContent;
drContent = cmdContent.ExecuteReader();
while (drContent.Read())
{
this.Add(new oTest( drContent.GetInt32(0) )); ///here is where it
goes wrong
}
drContent.Close();
Conn.Close();
}
}
-----------------
I have several collection classes that (could) derive from this class.
For example (and I would like to use it in this way, if possible):
public class ContentItemsTest : baseCollection
{
public ContentItemsTest(int iType)
{
Fill("SELECT as_ID FROM tblWhhatever" , new myItemClass());
}
}
-------------------------
The "baseCollection.Fill" doesn't know I'm sending a "myItemClass" as
object, and that's exactly what I want. Unfortunately this doesn't work.
Anyone any ideas?
cheers