SIGN UP MEMBER LOGIN:    
ARTICLE

Silverlight Login Registration Page Using LINQ to SQL And WCF: Part 1

Posted by Shirsendu Nandi Articles | Silverlight with C# June 23, 2011
In this article I will describe how to create a user registration page using Silverlight 3.0 and WCF and LINQ to SQL.
Reader Level:
Download Files:
 


For developing this Silverlight application you need Expression Blend in your system.

Step 1: Create a new Silverlight Project named "InsertData".

Now in the "Insertdata.Web" Project create a new LINQ to SQL page by clicking add new Item.

Give the new file name "silverlight.dbml".

Step 2:

Now click the Database explorer and connect to your database. For mine I have connected to the database. After that
I have the table name "tblTest". I drag this table into the "silverlight.dbml". Just like Fig 1 marked with red.

Fig 1:

LinqSql1.gif

You can create your own table with your database and drag and drop your table here. But remember your table must have a primary key. Otherwise the LINQ to SQL file will not work.

Step 3:

Now create a new Silverlight WCF file in the "Insertdata.web" Project and give it the name "servicerference1.svc"
just like fig 2.

LinqSql2.gif

Fig 2:

Step 4:

Now in the "Service1.svc.cs" file inder the Operation contract section write the method to insert data.
The code for that method is:

public void InsertData(string Username, string Password, string EmailId)
        {
            silverlightDataContext db = new silverlightDataContext();
            //tblUser row = new tblUser()
            //{
            //    UserName =Username ,
            //    PassWord =Password ,
            //};

            tblTest row = new tblTest()
            {
                Username =Username ,
                passWord =Password ,
                EmaidId =EmailId ,
            };
            //db.tblUsers.InsertOnSubmit(row);
            //db.SubmitChanges();
            db.tblTests.InsertOnSubmit(row);
            db.SubmitChanges();

        }

Here we create the object of our LINQ to SQL class; that means the silverlight.dbml. In here it will create like SilverlightdataContext.

After that we have to create the object of our table where we are to insert our data.
For my case my table is tbltest. We have to create the object of the table and have to add the column name. This method is for inserting the data into the database. Actually this WCF is for a business layer.

Here the full code of the WCF file is:

using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using System.Text;

namespace Insertdata.Web
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service1
    {
        [OperationContract]
        public void DoWork()
        {
            // Add your operation implementation here
            return;
        }
        [OperationContract]
        public void InsertData(string Username, string Password, string EmailId)
        {
            silverlightDataContext db = new silverlightDataContext();
            //tblUser row = new tblUser()
            //{
            //    UserName =Username ,
            //    PassWord =Password ,
            //};

            tblTest row = new tblTest()
            {
                Username =Username ,
                passWord =Password ,
                EmaidId =EmailId ,
            };
            //db.tblUsers.InsertOnSubmit(row);
            //db.SubmitChanges();
            db.tblTests.InsertOnSubmit(row);
            db.SubmitChanges();

        }
 
        // Add more operations here and mark them with [OperationContract]
    }
}


In my next article I will describe how to use this WCF insert function in the Silverlight UI page.

Login to add your contents and source code to this article
Article Extensions
Contents added by mahtab alam on Nov 16, 2011
share this article :
post comment
 

Waiting for IInd Part

Posted by surender bhyan Jun 23, 2011
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor