How to use the InfoMessage event : SQL Events « Database ADO.net « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Collections Data Structure
3. Components
4. Database ADO.net
5. Development Class
6. Event
7. File Stream
8. GUI Windows Form
9. Language Basics
10. Network
11. Office
12. Regular Expressions
13. Services Event
14. Thread
15. Web Services
16. Windows
17. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / C Sharp » Database ADO.net » SQL EventsScreenshots 
How to use the InfoMessage event


using System;
using System.Data;
using System.Data.SqlClient;

class InfoMessage
{
  public static void InfoMessageHandler(object mySender, SqlInfoMessageEventArgs myEvent)
  {
    Console.WriteLine("The following message was produced:\n" + myEvent.Errors[0]);
  }

  public static void Main(){
    SqlConnection mySqlConnection = new SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;");

    mySqlConnection.InfoMessage += new SqlInfoMessageEventHandler(InfoMessageHandler);

    mySqlConnection.Open();

    SqlCommand mySqlCommand = mySqlConnection.CreateCommand();

    mySqlCommand.CommandText = "PRINT 'This is the message from the PRINT statement'";
  
    mySqlCommand.ExecuteNonQuery();

    mySqlCommand.CommandText = "RAISERROR('This is the message from the RAISERROR statement', 10, 1)";
  
    mySqlCommand.ExecuteNonQuery();

    mySqlConnection.Close();
  }
}
           
       
Related examples in the same category
1. How to use the StateChange event
2. On row updating and updated event
3. Register two SqlConnection change events
w_ww__.__j___a__v__a__2___s___.c_o_m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.