简体   繁体   中英

How can I connect my silverlight application with SQL server 2005

I am trying to connect my silverlight application with Sql server 2005 for login purpose. I am totally new to silverlight and want to build my own website in Silverlight. Please suggest useful sites for referance. Thanx in advance.

You have to use a Web Service example WCF. 1) Add a WCF to your project.

//This is your interface Class.
 namespace SilverlightApplication1.Web
 {      
  [ServiceContract]
  public interface IService1
  {
    [OperationContract]
    bool UserLogin(string email, string password);
  }
 }

 //This is your service code behind class
 namespace SilverlightApplication1.Web
 {   
  public class Service1 : IService1
  {
    public bool UserLogin(string email,string password)
    {
                // Your logic here to verify user name and password
    }
  }
 }

 //After creating the service. Add a reference to your application.**

2) Add the Service Reference to your Silverlight application. Right click on your project, Select the web references option and add the service to your project. Now if you have a button control on your form which will submit the data to your wcf service. Add the following code in its click event.

 Service1Client proxy ; 
 private void button1_Click(object sender, RoutedEventArgs e)
    {
        proxy.UserLogin += new EventHandler<InsertDataCompletedEventArgs>(proxy_UserLogin);
        proxy.UserLogin(txtEmail.Text, "Password");
    }

   void proxy_UserLogin(object sender, InsertDataCompletedEventArgs e)
    {
        if (e.Result == true)
        {
            lblMesg.Content = "User Login successfully";
        }
        else
        {
            lblMesg.Content = "User record not found";
        }
    }

In the button Click event call that service.

If you want a SQL Server connection for logging on, you can create a Silverlight Business Application project. It has user logon built in. This way, you can concentrate on the rest of your Silverlight application's features.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM