Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - Database operations using Silverlight 2.0 ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Database operations using Silverlight 2.0 WCF and LINQ to SQL
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2008-12-10

    Table of Contents:
  • Database operations using Silverlight 2.0 WCF and LINQ to SQL
  • Developing a WCF Service to interact with LINQ to SQL for all CRUD operations
  • Developing a Silverlight 2.0 page to demonstrate CRUD functionality
  • Developing a Silverlight 2.0 page to demonstrate CRUD functionality: code behind
  • Developing a Silverlight 2.0 page to demonstrate CRUD functionality: Explanation

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Database operations using Silverlight 2.0 WCF and LINQ to SQL - Developing a Silverlight 2.0 page to demonstrate CRUD functionality: code behind


    (Page 4 of 5 )

    This is a continuation from the previous section. In the previous section, we developed the Siverlight 2.0 UI for CRUD operations against a WCF service. Now, we have to develop the code behind to access the WCF Service. Make sure that you have added a reference to the WCF service in your Silverlight 2.0 project.

    The following is the code behind for the UI markup provided in the previous section. The explanation is provided in the next section.


    Partial Public Class Page4

    Inherits UserControl


    Public Sub New()

    InitializeComponent()

    InitiateContext()

    InitiateHandlers()

    End Sub


    #Region "Declarations"


    Private objEmp As EmpService.Emp

    Dim objService As EmpService.EmpServiceClient


    #End Region


    #Region "Helpers"


    Private Sub InitiateContext()

    objService = New EmpService.EmpServiceClient

    objEmp = New EmpService.Emp

    DoBinding()

    End Sub


    Private Sub DoBinding()

    Me.LayoutRoot.DataContext = objEmp

    End Sub


    Private Sub InitiateHandlers()

    AddHandler objService.AddCompleted, AddressOf AddEmployeeCompleted

    AddHandler objService.UpdateCompleted, AddressOf UpdateEmployeeCompleted

    AddHandler objService.DeleteCompleted, AddressOf DeleteEmployeeCompleted

    AddHandler objService.GetEmployeeCompleted, AddressOf EmployeeFetched

    End Sub


    Private Sub ShowMessage(ByVal Msg As String)

    Me.lblMsg.Text = Msg

    End Sub


    #End Region


    #Region "Handlers"


    Private Sub AddEmployeeCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)

    ShowMessage("Added Successfully!")

    End Sub


    Private Sub UpdateEmployeeCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)

    ShowMessage("Updated Successfully!")

    End Sub


    Private Sub DeleteEmployeeCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)

    ShowMessage("Deleted Successfully!")

    btnClear_Click(Nothing, Nothing)

    End Sub


    Private Sub EmployeeFetched(ByVal sender As Object, ByVal e As EmpService.GetEmployeeCompletedEventArgs)

    If e.Result Is Nothing Then

    ShowMessage("Employee not found!")

    Else

    objEmp = e.Result

    DoBinding()

    ShowMessage("Fetched!")

    End If

    End Sub


    #End Region


    #Region "Button Events"


    Private Sub btnClear_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnClear.Click

    objEmp = New EmpService.Emp

    DoBinding()

    End Sub


    Private Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnAdd.Click

    ShowMessage("Communicating...")

    objService.AddAsync(objEmp)

    End Sub


    Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnDelete.Click

    ShowMessage("Communicating...")

    objService.DeleteAsync(objEmp.Empno)

    End Sub


    Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnUpdate.Click

    ShowMessage("Communicating...")

    objService.UpdateAsync(objEmp)

    End Sub


    Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSearch.Click

    ShowMessage("Communicating...")

    objService.GetEmployeeAsync(objEmp.Empno)

    End Sub


    #End Region



    End Class


    Press F5 and you should be able to do all CRUD operations against the “Emp” table in database using Silverlight 2.0 page together with WCF and LINQ to SQL.

    If you run into any problems, please refer tp my dedicated sections (especially on troubleshooting) in my previous articles. Please go through all of the troubleshooting steps in my previous articles; do so, and you should have no problems.

    More Windows Scripting Articles
    More By Jagadish Chaterjee


       · Hai,This is my next in series focusing on development using Silverlight 2.0, WCF...
       · Excellent Article. But is it the best solution or there are any other solutions as...
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek