473,383 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

delegates

Hi all,

I have a delegate of type OracleRowUpdatedEventArgs which is inherited
from System.Data.Common.RowUpdatedEventArgs and I have the
OleDbRowUpdatedEventArgs which is inherited from RowUpdatedEventArgs as
well. Saddly I can't create a delegate in this form:

oracleDataAdapter.RowUpdated +=
OracleRowUpdatedEventHandler(da_RowUpdated)

oleDbDataAdapter.RowUpdated +=
OleDbRowUpdatedEventHandler(da_RowUpdated)

private void da_RowUpdated(object sender, RowUpdatedEventArgs e) {}

because their events have different signatures:

private void oracleDataAdapter_RowUpdated (object sender,
OracleRowUpdatedEventArgs e){}

private void oleDbDataAdapter_RowUpdated (object sender,
OleDbRowUpdatedEventArgs e){}

I know it would be very simple to call the "da_RowUpdated"-Method from
oracleDataAdapter_RowUpdated and from oleDbDataAdapter_RowUpdated, but
sadly the event has to be set to an assembly which should be completely
database independent, so I have to look for a solution like the first
case.

Is there a possibility to "downcast" the events to RowUpdatedEventArgs
or does anybody knows a better solution?

Thanks in advance
Andy

Nov 17 '05 #1
4 2202
Would it be possible/viable to provide your own event handler/delegate in
which case you will have complete control ... for example:

public delegate DatabaseRowUpdatedEventHandler(object sender, MyEventArgs e)

public enum MyEventArgsTypes { ORACLE, OLE };
public class MyEventArgs : EventArgs
{
public readonly MyEventArgsTypes DatabaseType;
public MyEventArgs(EventArgs e, MyEventArgsTypes dbType) : base(e)
{
DatabaseType = dbType;
}
}
public class MyClass
{
public event DatabaseRowUpdatedEventHandler DatabaseRowUpdatedEvent;
public MyClass()
{
// other stuff
oracleDataAdapter.RowUpdated += OracleRowUpdatedEventHandler(_oracle);
oleDbDataAdapter.RowUpdated += OleDbRowUpdatedEventHandler(_ole);
}

private void _oracle(object sender, OracleRowUpdatedEventArgs e)
{
try
{
DatabaseRowUpdatedEvent(sender,
new MyEventArgs(e,
MyEventArgsTypes.ORACLE);
}
catch(NullReferenceException) { }
}
private void _ole(object sender, RowUpdatedEventArgs e)
{
try
{
DatabaseRowUpdatedEvent(sender,
new MyEventArgs(e,
MyEventArgsTypes.OLE);
}
catch(NullReferenceException) { }
}
}

--
--

Of all words of tongue and pen, the saddest are: "It might have been"
Nov 17 '05 #2
Hi billr,

unfortunately not. Because of the inner structure of the application, I
can't implement the class MyClass to encapsulate the DataDapters (some
parts are third party products and all the dataAdapters in the code are
generated in one static method which gives a IDbDataAdapter-Interface
back). I can access the original dataadapter only in the moment of
creation, after that I have only a IDbDataAdapter-Interface.

I guess I have to create an array and store the original dataadapters
and the accessory delegates. I assign the _oracle and _ole events like
your example and in _oracle/_ole I search the associated dataadapter in
addiction to the "sender" and so I can call the RowUpdatedEventArgs.
- just a little bit beside your idea :-)
- and sadly a little bit more unkind.

Thanks
Andy

Nov 17 '05 #3
Hi,
What you can do is create one method with each signature these method would
convert the different arguments they receive in a common format and then
call a method which does the work. Now alkl you have to do is creating a way
to transform both parameters ( those received in
OracleRowUpdatedEventHandler and OleDbRowUpdatedEventHandler ) in a common
format.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<am****@yahoo.de> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi all,

I have a delegate of type OracleRowUpdatedEventArgs which is inherited
from System.Data.Common.RowUpdatedEventArgs and I have the
OleDbRowUpdatedEventArgs which is inherited from RowUpdatedEventArgs as
well. Saddly I can't create a delegate in this form:

oracleDataAdapter.RowUpdated +=
OracleRowUpdatedEventHandler(da_RowUpdated)

oleDbDataAdapter.RowUpdated +=
OleDbRowUpdatedEventHandler(da_RowUpdated)

private void da_RowUpdated(object sender, RowUpdatedEventArgs e) {}

because their events have different signatures:

private void oracleDataAdapter_RowUpdated (object sender,
OracleRowUpdatedEventArgs e){}

private void oleDbDataAdapter_RowUpdated (object sender,
OleDbRowUpdatedEventArgs e){}

I know it would be very simple to call the "da_RowUpdated"-Method from
oracleDataAdapter_RowUpdated and from oleDbDataAdapter_RowUpdated, but
sadly the event has to be set to an assembly which should be completely
database independent, so I have to look for a solution like the first
case.

Is there a possibility to "downcast" the events to RowUpdatedEventArgs
or does anybody knows a better solution?

Thanks in advance
Andy

Nov 17 '05 #4
Hi,

because there are more than one dataadapter and all of them are created
in a single static Method which returns an IDbDataAdapter-Interface the
challenge is exact the transformation - see my answer to billr

Thanks
Andy

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jeffrey T. Smith | last post by:
Back when the new J2SE1.5 features were announced, there was a JavaLive community chat (http://java.sun.com/developer/community/chat/JavaLive/2003/jl0729.html) in which Neal Gafter explains the...
3
by: Sam | last post by:
I’m just starting to learn delegates. I’m at the very beginning. If I understand correctly, delegates are for when you want to pass a function as a parameter. For example the client provides a...
4
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on...
4
by: AMDRIT | last post by:
I am trying to understand Delegates and where/when to use them. I can see one potential use of a delegate (on form closing, set the cancel property in the event arguments.) Does anyone have a...
6
by: =?Utf-8?B?Sko=?= | last post by:
I have a logger component that logs to multiple sources, ie textfile, eventlog etc. and I have two methods that depending on where I call up my logger comp. one of them will be called. For ex. if...
0
by: bharathreddy | last post by:
Delegates Here in this article I will explain about delegates in brief. Some important points about delegates. This article is meant to only those who already know delegates, it will be a quick...
6
by: =?Utf-8?B?T2xkQ2FEb2c=?= | last post by:
My question is regarding the use of delegates in C#. I see how .Net uses delegates to wire event handlers to events. It’s an object created by a single line of code by the system and that makes...
7
by: Siegfried Heintze | last post by:
I'm studying the book "Microsoft Visual Basic.NET Language Reference" and I would like some clarify the difference between events and delegates. On page 156 I see a WinForms example of timer that...
69
by: raylopez99 | last post by:
They usually don't teach you in most textbooks I've seen that delegates can be used to call class methods from classes that are 'unaware' of the delegate, so long as the class has the same...
9
by: raylopez99 | last post by:
Hello all— I’m trying to get the below to work and cannot get the format right. It’s from this example: http://msdn.microsoft.com/en-us/library/8627sbea(VS.71).aspx What it is: I’m trying...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.