Salakhetdinov Shamil
mcp2004 at mail.ru
Mon Apr 23 04:18:56 CDT 2012
Use virtual method in the base class and override it in a derived class. /SS-wp7 Sun, 22 Apr 2012 23:39:41 -0400 от jwcolby <jwcolby at colbyconsulting.com>: > Yep, it seems that way, except that the while loop really is "common" to the > base and the derived, > only the mErrFactory actually is different. Having to carve the While loop > out adds another > function to both base and derived. > > John W. Colby > Colby Consulting > > Reality is what refuses to go away > when you do not believe in it > > On 4/22/2012 11:21 PM, Arthur Fuller wrote: > > I know much less than you about C# but what you want to do seems like a > > violation of the intended design. Anything the base class needs should live > > in it, not beneath it, no? > > > > A. > > > > On Sun, Apr 22, 2012 at 10:28 PM, jwcolby<jwcolby at colbyconsulting.com>wrote: > > > >> I have the following code which is in the base class: > >> > >> protected bool mLoadFromSQLSrvr(string SQL) > >> { > >> try > >> { > >> cnn = new SqlConnection(clsGlobals.**myConnection); > >> cnn.Open(); > >> cmd = new SqlCommand(SQL, cnn); > >> dr = cmd.ExecuteReader(); > >> while ((dr.Read())) > >> { > >> mErrFactory(); > >> } > >> } > >> catch (SqlException ex) > >> { > >> > >> The problem is that mErrFactory is different in the base and derived > >> class. Can this code be told to call the mErrFactory in the derived class? > >> Or do I need to just carve out the while loop and have this method just > >> get the data reader something like this: > >> > >> protected bool mSQLSrvrReader(string SQL) > >> { > >> try > >> { > >> cnn = new SqlConnection(clsGlobals.**myConnection); > >> cnn.Open(); > >> cmd = new SqlCommand(SQL, cnn); > >> dr = cmd.ExecuteReader(); > >> return true; > >> } > >> } > >> > >> private bool mLoadFromSQLSrvr(string SQL) > >> { > >> > >> if mSQLSrvrReader(strsql) > >> { > >> while ((dr.Read())) > >> { > >> mErrFactory(); > >> } > >> > >> } > >> } > >> > >> Then override mLoadFromSqlServer in the derived class? > >> > >> Since I know how to do the latter I am going there but I am wondering > >> whether the base can be told to call an identically named method down in a > >> derived class. It seems unlikely but what do I know? > >> -- > >> John W. Colby > >> Colby Consulting > >> > >> Reality is what refuses to go away > >> when you do not believe in it > >> > >> ______________________________**_________________ > >> dba-VB mailing list > >> dba-VB at databaseadvisors.com > >> > http://databaseadvisors.com/**mailman/listinfo/dba-vb<http://databaseadvisors.com/mailman/listinfo/dba-vb> > >> http://www.databaseadvisors.**com<http://www.databaseadvisors.com> > >> > >> > > > > > > _______________________________________________ > dba-VB mailing list > dba-VB at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-vb > http://www.databaseadvisors.com