简体   繁体   English

如何将我的silverlight应用程序与SQL Server 2005连接

[英]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. 我正在尝试将我的silverlight应用程序与Sql server 2005连接以进行登录。 I am totally new to silverlight and want to build my own website in Silverlight. 我对Silverlight很新,想在Silverlight中建立自己的网站。 Please suggest useful sites for referance. 请建议有用的网站以供参考。 Thanx in advance. Thanx提前。

You have to use a Web Service example WCF. 您必须使用Web服务示例WCF。 1) Add a WCF to your project. 1) 向项目添加WCF。

//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. 2) 将服务引用添加到Silverlight应用程序。 Right click on your project, Select the web references option and add the service to your project. 右键单击项目,选择Web引用选项并将服务添加到项目中。 Now if you have a button control on your form which will submit the data to your wcf service. 现在,如果您的表单上有一个按钮控件,它将把数据提交给您的wcf服务。 Add the following code in its click event. 在其click事件中添加以下代码。

 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. 在按钮Click事件中调用该服务。

If you want a SQL Server connection for logging on, you can create a Silverlight Business Application project. 如果要使用SQL Server连接进行登录,可以创建Silverlight业务应用程序项目。 It has user logon built in. This way, you can concentrate on the rest of your Silverlight application's features. 它内置了用户登录。这样,您可以专注于Silverlight应用程序的其余功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用SQL Server 2005连接和插入ASP? - how to connect and insert the ASP with sql server 2005? ASP.net应用程序无法连接到SQL Server 2005数据库 - ASP.net application can't connect to sql server 2005 database 如何在sql server 2005中创建到列的动态行? - How Can I Create Dynamic Rows to Columns in sql server 2005? 如何将SQL Server和Android应用程序与Push集成 - How can I integrate SQL Server and my android application with Push 如何将Visual Studio 2010网站连接到SQL Server 2005 - How to connect a Visual Studio 2010 website to SQL Server 2005 如何使用SQL Server和Asp.net在专用服务器中部署Web应用程序? - How can I deploy my web application In dedicated server using SQL Server and Asp.net? 无法连接到远程SQL Server 2005 - Unable to connect to remote SQL Server 2005 我可以使用SQL Server安全性来控制对(数据库优先)ASP.net应用程序的访问吗? 怎么样? - Can I use SQL Server security to control access to my (database first) ASP.net application? How? 如何在Silverlight 4.0应用程序后面的asp页上打开iframe,而看不到它 - How can I open an iframe on the asp page behind my Silverlight 4.0 Application without it being visible 如何将现有的业务层实现到SilverLight 4.0应用程序? - How can I implement my existing Business Layer to a SilverLight 4.0 Application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM