Silverlight / WPF - Database Connection

Asked By Rajendra
05-Jul-11 07:42 AM
how to connect to database in silverlight 4?? i want to display data in gridview
  James H replied to Rajendra
05-Jul-11 07:43 AM

Check this link it contains a great set of documentation on using ADO.Net data services in Silverlight.

I found one more good article so editing my answer.... but its the luck if this works for you if not then author of the article donot respond :( quite sad...

Here is the best link i found hurry!!! It solves the problem

  Web Star replied to Rajendra
05-Jul-11 07:44 AM
There are good example with code how can you bind data in silverlight
http://www.codeproject.com/KB/silverlight/CntDbSlght.aspx
  Ravi S replied to Rajendra
05-Jul-11 07:44 AM
HI

You can't communicate with database directly from Silverlight.  DataSet is not currently available in Silverlight too. So, you need to use web service to communicate with database.

You can check the links below


refer the links also
http://michaelsync.net/2008/03/10/silverlight-2-beta1-database-operations-with-aspnet-web-service-in-silverlight-2
  Ravi S replied to Rajendra
05-Jul-11 07:46 AM
Hi

use this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace SilverlightWcfService
{
   
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "DatabaseService" in code, svc and config file together.
   
public class DatabaseService : IDatabaseService
   
{
       
string myConnectionString = "someConnectionString";

       
public List<string> GetNames()
       
{
           
List<string> list = new List<string>();

           
using (SqlConnection cn = new SqlConnection(myConnectionString))
           
{
               
using (SqlCommand cmd = cn.CreateCommand())
               
{
                    cmd
.CommandText = "SELECT FirstName + ' ' + LastName FROM Person";
                    cmd
.CommandType = CommandType.Text;

                    cn
.Open();

                   
using (SqlDataReader dr = cmd.ExecuteReader())
                   
{
                       
while (dr.Read())
                       
{
                            list
.Add(dr.GetString(0));
                       
}
                   
}
               
}
           
}

           
return list;
       
}
   
}
}

refer the link for whole details and code
http://eclipsed4utoo.com/blog/silverlight-connecting-remote-database-wcf/
  Reena Jain replied to Rajendra
05-Jul-11 07:47 AM
Hi,

Try this
  1. Created Silverlight 4 web application in Visual Studio 2010 (Windows 7)
  2. Added a SQL database to the "App_Data" folder on the ASP.NET side of the website called "aspnetdb.mdf".  I'm running SQL Server Express on my machine.
  3. Wrote a simple WCF webservice that returns all of the Table names in the database. 
  4. The ConnectionString which works very well when I'm running the Silverlight app in VS 2010 for debugging is:
string ConnectionString = @"data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true";

Hope this will help you
  dipa ahuja replied to Rajendra
05-Jul-11 08:02 AM
You can create webservice to bind you data with silverlight griview check this article
http://viralsarvaiya.wordpress.com/2010/09/17/bind-silverlight-grid-view-with-wcf-service/
  Vickey F replied to Rajendra
05-Jul-11 09:40 AM

The basic steps for populating a DataGrid in a Silverlight application are:

1) Drag and drop a DataGrid control from the toolbox onto the desired page.

2) Build/generate the business objects that contains the data for the grid.

3) Bind the business objects to the data grid using the DataGrid's ItemsSource.

Step 1 is self explanatory. If you are working through the set of blog posts, add the grid to the Students page. Otherwise, add a grid to any page.

Be sure to set the AutoGenerateColumns property to True so it will automatically show your data.

The Silverlight page is called a "View" because it is the user's view of the application. It is the part of the application that the user sees and interacts with.

Step 2 requires a fundamental decision on how you will get data into your application. The primary choices are:

  • Build an entity class in the Silverlight application that is populated from a WCF service.
  • Generate an entity class in the Silverlight application using WCF RIA services and Entity Framework.
  • Generate an entity class in the Silverlight application using WCF RIA services and your business objects (sometimes called Plain Old CLR Objects or POCOs). See this prior post for more information on using WCF RIA with your business objects.

Follow this link for more detail-

http://msmvps.com/blogs/deborahk/archive/2011/01/22/populating-a-datagrid-in-a-silverlight-application.aspx

http://www.codeproject.com/KB/silverlight/SilverlightDGFromMDB.aspx
(using WCF service)

Hope this will help you.

  Riley K replied to Rajendra
05-Jul-11 10:06 AM
  jason rle replied to Rajendra
07-Jul-11 05:30 AM
The Silverlight is running on client and it has no any database support, so you could not directly access a database.
You should not put your business components on client. It's bettern to put all business components on server end and use WCF to communicate between them.
Create New Account
help
attempted to be installed. [08 / 10 / 11, 14:26:01] VS70pgui: [2] DepCheck indicates Microsoft Silverlight was not attempted to be installed. [08 / 10 / 11, 14:26:01] VS70pgui: [2] DepCheck indicates Microsoft Silverlight 3 SDK was not attempted to be installed. [08 / 10 / 11, 14:26:01] VS70pgui attempted to be installed. [08 / 10 / 11, 14:26:01] VS70pgui: [2] DepCheck indicates Microsoft SQL Server Compact 3.5 SP2 (x86) ENU was not attempted to be installed. [08 / 10 / 11, 14:26:01] VS70pgui: [2] DepCheck indicates Visual Studio 2010 Tools for SQL Server Compact 3.5 SP2 ENU was not attempted to be installed. [08 / 10 / 11, 14 attempted to be installed. [08 / 10 / 11, 14:26:02] VS70pgui: [2] DepCheck indicates Microsoft SQL Publishing Wizard 1.4 was not attempted to be installed. [08 / 10 / 11, 14:26:02] VS70pgui: [2] DepCheck indicates Microsoft SQL Server System CLR Types was not attempted to be installed. [08 / 10 / 11, 14:26
SQL Server 2008 Standard and Visual Studio 2008 Professonal SQL Server I have retailed copies VS 2008 Pro and SQL 2008 Standard. While in VS 2008 I tried to create a SQL database in a ASP.Net 3.51 Web application. I'm getting an error saying I need to install SQL Server 2005 Express Edition. I have all the current patches and upgrades to both programs. I
SQL 2008 Won't Install SQL Server I reinstalled SQL Server 2008 on my local development machine today. I reinstalled because I could not install the SilverLight development tools on the local machine. I recalled from some earlier issues that SQL Server installed a crippled version of Visual Studio and suspected this to be the problme. I
Cannot connect to SSIS after Windows update SQL Server Hi, I received the following error when trying to open SQL Server 2005 Integration Services via MS SQL Server Management Studio: request. (Microsoft.SqlServer.SmoEnum). Connect to SSIS Service on machine "<servername> " failed: Error loading type library / DLL." I can open the Database Engine fine on that SQL 2005 server. This problem occurred after installing Windows Update, which installed the following 8 items: Windows Server
Binding data from sql server to silverlight grid Hi, Im very new to silverlight. How we can fetch data from sql server and binding to silverlight grid. . Please help me in this regard. Thanks. HI refer this example http: / / www.codeproject.com / KB / silverlight / Silverlight3_SQL_WCF.aspx HI here is the example The DataGrid image refer the link for details