hi,
I'm trying to fill a collection using the following 'generic' code:
-----------------
public class baseCollection : System.Collecti ons.CollectionB ase
{
protected void Fill(string strSQL, object oTest)
{
SqlConnection Conn = new SqlConnection(S ettings.sDBConn );
Conn.Open();
SqlCommand cmdContent = new SqlCommand(strS QL, Conn);
SqlDataReader drContent;
drContent = cmdContent.Exec uteReader();
while (drContent.Read ())
{
this.Add(new oTest( drContent.GetIn t32(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 ContentItemsTes t : baseCollection
{
public ContentItemsTes t(int iType)
{
Fill("SELECT as_ID FROM tblWhhatever" , new myItemClass());
}
}
-------------------------
The "baseCollection .Fill" doesn't know I'm sending a "myItemClas s" as
object, and that's exactly what I want. Unfortunately this doesn't work.
Anyone any ideas?
cheers 4 1811
First, oTest is an instance of an object. New requires a type, not an
instance.
DalePres
"rapataa" <dg@rapataa.fru p> wrote in message
news:c0******** *************** ****@msgid.xeno site.net... hi,
I'm trying to fill a collection using the following 'generic' code: ----------------- public class baseCollection : System.Collecti ons.CollectionB ase { protected void Fill(string strSQL, object oTest) { SqlConnection Conn = new SqlConnection(S ettings.sDBConn ); Conn.Open(); SqlCommand cmdContent = new SqlCommand(strS QL, Conn); SqlDataReader drContent; drContent = cmdContent.Exec uteReader(); while (drContent.Read ()) { this.Add(new oTest( drContent.GetIn t32(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 ContentItemsTes t : baseCollection { public ContentItemsTes t(int iType) { Fill("SELECT as_ID FROM tblWhhatever" , new myItemClass()); } } ------------------------- The "baseCollection .Fill" doesn't know I'm sending a "myItemClas s" as object, and that's exactly what I want. Unfortunately this doesn't work. Anyone any ideas?
cheers
hi-
DalePres is right- you probably wanna say something like:
this.Add(typeof (MyItemClass)oT est);
or assign it earlier:
MyItemClass mIC = (MyItemClass)oT est;
Now all the properties of the class are exposed and you can add whatever you need
ie this.Add(mIC.Na me);
I wasn't able to work out what you were adding to the collection so sorry this is a bad example First, oTest is an instance of an object. New requires a type, not an instance.
DalePres
"rapataa" <dg@rapataa.fru p> wrote in message news:c0******** *************** ****@msgid.xeno site.net... hi,
I'm trying to fill a collection using the following 'generic' code: ----------------- public class baseCollection : System.Collecti ons.CollectionB ase { protected void Fill(string strSQL, object oTest) { SqlConnection Conn = new SqlConnection(S ettings.sDBConn ); Conn.Open(); SqlCommand cmdContent = new SqlCommand(strS QL, Conn); SqlDataReader drContent; drContent = cmdContent.Exec uteReader(); while (drContent.Read ()) { this.Add(new oTest( drContent.GetIn t32(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 ContentItemsTes t : baseCollection { public ContentItemsTes t(int iType) { Fill("SELECT as_ID FROM tblWhhatever" , new myItemClass()); } } ------------------------- The "baseCollection .Fill" doesn't know I'm sending a "myItemClas s" as object, and that's exactly what I want. Unfortunately this doesn't work. Anyone any ideas? cheers
hmmm, that first construct with typeof won't compile. What were you trying to suggest with that one?
From looking at the code I would guess that the OP needs to use the type name of oTest rather than oTest in the new construct - I assume that it has a constructor that takes an int
But without more details abiout the type of oTest and what the Add method takes its hard to work out what the solution is
Regards
Richard Blewett - DevelopMentor http://www.dotnetconsult.co.uk/weblog http://www.dotnetconsult.co.uk
hi-
DalePres is right- you probably wanna say something like:
this.Add(typeof (MyItemClass)oT est);
or assign it earlier:
MyItemClass mIC = (MyItemClass)oT est;
Now all the properties of the class are exposed and you can add whatever you need
ie this.Add(mIC.Na me);
I wasn't able to work out what you were adding to the collection so sorry this is a bad example
let's say there's a Plumber object.
The collection object "Plumbers" will be filled based on the Plumbers in
tblPlumber
strSQL = "SELECT ID FROM tblPlumber"
This string is send to the base collection object ( "public class
baseCollection : System.Collecti ons.CollectionB ase" ) together.
The void "Fill" will use the plumber info from the DB to fill the collection
object with objects of type "Plumber". The constructor of Plumber takes an
int.
It's also possible to create a (second) "Add" function in the derived class,
but I think that's butt_ugly.
--------
"Richard Blewett [DevelopMentor]" <ri******@NOSPA Mdevelop.com> wrote in
message news:e$******** ******@TK2MSFTN GP09.phx.gbl... hmmm, that first construct with typeof won't compile. What were you trying
to suggest with that one? From looking at the code I would guess that the OP needs to use the type
name of oTest rather than oTest in the new construct - I assume that it has
a constructor that takes an int But without more details abiout the type of oTest and what the Add method
takes its hard to work out what the solution is Regards
Richard Blewett - DevelopMentor http://www.dotnetconsult.co.uk/weblog http://www.dotnetconsult.co.uk
hi-
DalePres is right- you probably wanna say something like:
this.Add(typeof (MyItemClass)oT est);
or assign it earlier:
MyItemClass mIC = (MyItemClass)oT est;
Now all the properties of the class are exposed and you can add whatever
you need ie this.Add(mIC.Na me);
I wasn't able to work out what you were adding to the collection so sorry
this is a bad example This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: DKode |
last post by:
Ok,
here is another question I have that is sort of unrelated to my last
posting about composition.
I have three Collection classes:
EmployeeCollection
HourCollection
InfractionCollection
|
by: Arpan |
last post by:
<%
If(False) Then
Response.Write("False")
Else
Response.Write("True")
End If
%>
In the above code, the Else condition will be executed. Why?
|
by: Michel |
last post by:
Hi there,
What is the best way to serialize unknown data?
I have a class that contains a list of parameter objects.
The parameter has a value which can be a simple value of a complex class,
e.g.
class param {
object value;
}
|
by: Dan Noel |
last post by:
I am implementing a DataStore/Settings object that stores objects in XML by
serializing the objects in XML and then associating these objects with key
names.
At some later point, I want to retrieve the object associated with a given
keyname, but I am running into trouble deserializing objects into the correct
object type.
Nearly all of the examples that I have found that use XmlSerializer pass in
a type ahead of time, but in my case...
|
by: jab3 |
last post by:
(again :))
Hello everyone.
I'll ask this even at risk of being accused of not researching adequately.
My question (before longer reasoning) is: How does declaring (or defining,
whatever) a variable **var make it an array of pointers?
I realize that 'char **var' is a pointer to a pointer of type char (I hope).
And I realize that with var, var is actually a memory address (or at
| |
by: Michael Maes |
last post by:
Hi,
I have a BaseClass from which many Classes Derive.
In short: the BaseClass provides the functionalities (Methods) and the Derived Classes extend it with Properties.
One of the (Base) Functionalities is to (De)Serialize the Objects.
Deserialization is performed in the BaseClass
Friend Function PerformDeserialization(ByVal path As String, ByVal user As String) As Object
Debug.WriteLine("Settings.BaseSettings.PerformDeserialization")...
|
by: Juha Nieminen |
last post by:
I'm sure this is not a new idea, but I have never heard about it
before. I'm wondering if this could work:
Assume that you have a common base class and a bunch of classes
derived from it, and you want to make a deque which can contain any
objects of any of those types. Normally what you would have to do is to
make a deque or vector of pointers of the base class type and then
allocate each object dynamically with 'new' and store the...
|
by: mdh |
last post by:
Hi All,
The section is titled Variable-length Argument lists.
May I ask a question about the use of "macros".
To quote K&R.
"The standard header <stdarg.hcontains a set of macro definitions
that define how to step through an argument list...... The type
va_list is used to declare a variable...in minprintf..ap
.......The macro va_start initializes ap to point to the first unnamed
argument."
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |