473,387 Members | 1,650 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,387 software developers and data experts.

HELP! Simple delegation won't work!

I am a C# newbie with experience in other languages who is writing a C# app
that talks to a SQL Server. I have the connection working, the queries are
working, error handling (try/catch/finally) is working, and life is (mostly)
good. However, I tried to use a delegate to display informational and
warning message (these are non-error messages not trapped by catch) and this
is *not* working. Here is what I believe to be the relevant part of my
code. I am calling a SQL Server stored procedure that I *know* raises a
message with severity level of 10 (informational), but doing a step-through
shows that my handler is not firing at all. What am I missing? The
following code is inside my form class (it's a thick-client app), if that
matters.

public delegate void OleDbInfoMessageEventHandler (Object sender,
OleDbInfoMessageEventArgs e);

public class DBMessageHandler
{
public static void MessageHandler (Object sender,
OleDbInfoMessageEventArgs e)
{
int i;
for (i = 0; i < e.Errors.Count; i++)
{
MessageBox.Show (e.Errors[i].ToString());
}
}
}

//DBMessageHandler dbmh = new DBMessageHandler();
OleDbInfoMessageEventHandler dbmh = new
OleDbInfoMessageEventHandler(DBMessageHandler.Mess ageHandler);


Jul 21 '05 #1
2 1275
Hi Chris,

How are you invoking your delegate?

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Chris Leonard" <s_***********@hotmail.com> wrote in message
news:XP****************@news.uswest.net...
I am a C# newbie with experience in other languages who is writing a C# app that talks to a SQL Server. I have the connection working, the queries are working, error handling (try/catch/finally) is working, and life is (mostly) good. However, I tried to use a delegate to display informational and
warning message (these are non-error messages not trapped by catch) and this is *not* working. Here is what I believe to be the relevant part of my
code. I am calling a SQL Server stored procedure that I *know* raises a
message with severity level of 10 (informational), but doing a step-through shows that my handler is not firing at all. What am I missing? The
following code is inside my form class (it's a thick-client app), if that
matters.

public delegate void OleDbInfoMessageEventHandler (Object sender,
OleDbInfoMessageEventArgs e);

public class DBMessageHandler
{
public static void MessageHandler (Object sender,
OleDbInfoMessageEventArgs e)
{
int i;
for (i = 0; i < e.Errors.Count; i++)
{
MessageBox.Show (e.Errors[i].ToString());
}
}
}

//DBMessageHandler dbmh = new DBMessageHandler();
OleDbInfoMessageEventHandler dbmh = new
OleDbInfoMessageEventHandler(DBMessageHandler.Mess ageHandler);

Jul 21 '05 #2
Hello Miha, and thanks for your reply. Though it took me a while to figure
it out, my problem was that I was trying to follow the samples at
http://msdn.microsoft.com/library/de...sdelegates.asp,
but I really needed the simpler samples which I eventually found at
http://msdn.microsoft.com/library/de...tionevents.asp.
I'm still not sure why my original attempts (from the first samples) failed,
but I think I was trying to write code as though I were publishing an event
instead of subscribing to it. In any event (no pun intended), your simple
questions got me thinking, and eventually I found the right stuff. Thanks
again for the reply.

Chris

"Miha Markic" <miha at rthand com> wrote in message
news:eV**************@TK2MSFTNGP09.phx.gbl...
Hi Chris,

How are you invoking your delegate?

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Chris Leonard" <s_***********@hotmail.com> wrote in message
news:XP****************@news.uswest.net...
I am a C# newbie with experience in other languages who is writing a C#

app
that talks to a SQL Server. I have the connection working, the queries

are
working, error handling (try/catch/finally) is working, and life is

(mostly)
good. However, I tried to use a delegate to display informational and
warning message (these are non-error messages not trapped by catch) and

this
is *not* working. Here is what I believe to be the relevant part of my
code. I am calling a SQL Server stored procedure that I *know* raises a
message with severity level of 10 (informational), but doing a

step-through
shows that my handler is not firing at all. What am I missing? The
following code is inside my form class (it's a thick-client app), if that matters.

public delegate void OleDbInfoMessageEventHandler (Object sender,
OleDbInfoMessageEventArgs e);

public class DBMessageHandler
{
public static void MessageHandler (Object sender,
OleDbInfoMessageEventArgs e)
{
int i;
for (i = 0; i < e.Errors.Count; i++)
{
MessageBox.Show (e.Errors[i].ToString());
}
}
}

//DBMessageHandler dbmh = new DBMessageHandler();
OleDbInfoMessageEventHandler dbmh = new
OleDbInfoMessageEventHandler(DBMessageHandler.Mess ageHandler);


Jul 21 '05 #3

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

Similar topics

6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.