Click here to Skip to main content
11,478,619 members (67,820 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Silverlight
ı have one silverlight application and ı need to read data from ms access database, but ı cant use "oldb", and ı dont know another way, how can ı connect it?

thanks
Posted 3-Aug-11 13:50pm
bytbty331
Edited 3-Aug-11 21:15pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to write server side code to connect to the database and then get values returned to the Silverlight client.
This would be done via a web service.
  Permalink  
Comments
bytbty at 4-Aug-11 5:25am
   
just this way or it has another way for solving my problem, thanks
bytbty at 4-Aug-11 5:25am
   
it is a bit complicated :(
bytbty at 4-Aug-11 5:36am
   
or can you put code? thanks
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

just follow these steps.
1.create a silverlight application.
2.right click the web project and add new item and add the "Silverlight-enabled Wcf service".
3.in the wcf service add the method u want to access the databases.
4.its the same way how u do in your code behind.in Silverlight u cant reach database directly.u can reach database only through services.
5.add a service referrence to ur silverlight project.right click the refrence and click "Add service references" and select the wcf service that u created and give a name for it.
6.now go to your codebehind or where u want to access the database.
7.create a client for the service that u referred.
then using the client u will be getting a ASYNCHRONOUS method for each method u created in wcf service.

for ex:- if u created a method "GetEmployees" in WCF service,in ur code behind using service client u will get a name called GetEmployeesAsync through which can access the method in WCF service and data base will be accessed from service.

8.The same way u have to do with using oldb namespace..the rest are same as usual..

FOR FURTHER CLEAR APPROACH WITH SCREENSHOTS VISIT THIS BLOG:
http://swayingtheworld.blogspot.com/2011/08/accessing-databases-in-silverlight.html
  Permalink  
v2
Comments
bytbty at 4-Aug-11 12:54pm
   
ı try this but, ı cant solve my promlem thanks :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

look dear its possible and its very very easy too...
for accessing MS ACCESS u need to add this namespace "system.data.oledb".
but this namespace wont be available in ur silverlight application.THIS NAMESPACE WILL BE AVAILABLE ONLY IN THE WEB PROJECT,i.e WCF SERVICE THAT U R USING...

i will write a sample code here..but just follow the logic of it!
this is in the wcf service..ok?
right click the web project and add new item called "Silverlight-Enabled Wcf service" and name it as SampleService. and some thing like this that follows...

using system;
using System.Data.SqlClient;
using System.Data;

namespace TimeManagement.Web
{
      [DataContract]
      public class Employee
      {
      [DataMember(Order = 0)]
            public string EmployeeID { get; set; }
            [DataMember(Order = 1)]
            public string FirstName { get; set; }
            [DataMember(Order = 2)]
            public string LastName { get; set; }
            [DataMember(Order = 3)]
            public string EmailAddress { get; set; }
      }
[ServiceContract(Namespace = "")]
      [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
      public class SampleService
      {
            [OperationContract]
            public int InsertEmployee(string Firstname, string Lastname, string EmployeeId,string Email)
            {
            //do ur string connections
            //and insert the datas to ur msaccess tables.
            //its nearly the same how u use to connect with sql.
            //since its returning integer use executenonquery to return ur values.
            }
}

now in ur silverlight application..in reference right click and add new service reference and name it sampleserviceRef...
now go to the page where u want to insert ur datas to access database and do the following...

public void InsertEmployee(string Firstname, string Lastname, string EmployeeId, string Email)
            {
               //creating client for the service
                  var SerObj = new SampleServiceRef.TMServiceClient();                 
                  SerObj.InsertEmployeeAsync(Firstname, Lastname, EmployeeId,Email);
            }

thats it values are inserted...
u cant directly communicate to database in silverlight because silverlight is a clientside application..u can communicate to database only through WCF service!!!
if u still cant understand,tell me ur queries..let me explain u!!!
  Permalink  
Comments
Member 4179883 at 8-Dec-11 14:22pm
   
Works wonderfully, thanks a lot...
Question, how do I add a second Class for another Access DB table, say I have a table called EmployeeBenefits?
Following your sample I created another class just like Employee:
[DataContract]
public class EmployeeBenefits
{
[DataMember(Order = 0)]
public string EmployeeID { get; set; }
[DataMember(Order = 1)]
public Nullable HireDate { get; set; }
[DataMember(Order = 2)]
public Nullable BenefitStartDate { get; set; }
...
}

But class is not available as a Datasource on the client as Employee class is

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 229
1 F-ES Sitecore 170
2 Sascha Lefèvre 160
3 Frankie-C 120
4 OriginalGriff 105
0 Sergey Alexandrovich Kryukov 7,675
1 OriginalGriff 7,321
2 Sascha Lefèvre 3,034
3 Maciej Los 2,491
4 Richard Deeming 2,325


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 5 Aug 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100