Querying attribute and node values of XML data in SQL

DECLARE @xmlData xml

set @xmlData = '<University Name="VTU">
 <COLLEGE Name="SJCE">
 <DESCRIPTION>SJCE Mysore</DESCRIPTION>
 <Address field="State">Karnataka</Address> 
 <Address field="Country">India</Address> 
 </COLLEGE>
<COLLEGE Name="NIE">
 <DESCRIPTION>NIE Mysore</DESCRIPTION>
 <Address field="State">Karnataka</Address> 
 <Address field="Country">India</Address> 
 </COLLEGE>
 </University>'

SELECT 
 U.C.value('(@Name)[1]', 'varchar(max)') as CollegeName,
 U.C.value('(DESCRIPTION)[1]', 'varchar(max)') as CollegeDescription ,
 U.C.value('(Address[@field="State"])[1]', 'varchar(max)') as StateName,
 U.C.value('(Address[@field="Country"])[1]', 'varchar(max)') as CountryName
FROM @xmlData.nodes('/University/COLLEGE') as U(C)

The above SELECT SQL Query will display below result:

XmlQueryResult

WPF – Getting Started

Simple Getting started WPF Example code that uses the InkCanvas control.

XAML code:

<Window x:Class="InkCanvasWpfApplication.InkCanvasTest"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Ink Canvas" Height="450" Width="600" Background="LightBlue" >
    <Grid>
        <InkCanvas Height="Auto" HorizontalAlignment="Stretch" Margin="9,9,9,68" Name="inkCanvas1" VerticalAlignment="Stretch" Width="Auto" Background="LightYellow"/>
        <Button Content="Clear" Height="23" HorizontalAlignment="Left" Margin="50,365,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
        <Button Content="Close" Height="23" HorizontalAlignment="Left" Margin="477,365,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
    </Grid>
</Window>

Code behind C# Code:

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            this.inkCanvas1.Strokes.Clear();            
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

 

References: http://msdn.microsoft.com/en-us/library/bb820878%28v=vs.90%29.aspx

Calling Functions Asynchronously

using System.Threading;
using System.Runtime.Remoting.Messaging;


        //Delegate to Asynchronous Method 
        private delegate bool DelegateTestAsyncMethod(ref string statusLog);

        //Asynchronous - Method
        private bool AsyncTesting(ref string statusLog)
        {
            //Some logic here
            Thread.Sleep(1500);           

            //Update Reference parameter
            statusLog += "Function had run successfully.";
                        
            return true;
        }

        //Asynchronous - CallBack Method
        private void CallbackAsyncTesting(IAsyncResult ar)
        {
            AsyncResult result = (AsyncResult)ar;

            //Variable to retrieve Ref Parameter
            string retStatusLog = string.Empty;

            DelegateTestAsyncMethod objTestAsyncMethod = (DelegateTestAsyncMethod)result.AsyncDelegate;
            bool returnValue = objTestAsyncMethod.EndInvoke(ref retStatusLog, ar);           
        }


        //Button Click Event to test Asynchronous codes.
        private void ButtonTest_Click(object sender, EventArgs e)
        {
            //Reference Parameter to pass
            string statusLog = string.Empty;

            // Call to Asynchronous Method
            DelegateTestAsyncMethod objTestAsyncMethod = new DelegateTestAsyncMethod(AsyncTesting);
            objTestAsyncMethod.BeginInvoke(ref statusLog, new AsyncCallback(CallbackAsyncTesting), null);
        }