如何在silverlightapplicatipon中连接MS Access数据库? [英] how to connection MS access database in silverlightapplicatipon?

查看:92
本文介绍了如何在silverlightapplicatipon中连接MS Access数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ı有一个Silverlight应用程序,并且ı需要从ms Access数据库读取数据,但是ı不能使用"oldb",并且ı不知道另一种方式,该如何连接它?
谢谢

ı 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

推荐答案

您需要编写服务器端代码以连接到数据库,然后将值返回给Silverlight客户端.
这将通过Web服务完成.
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.


只需按照以下步骤操作即可.
1.创建一个Silverlight应用程序.
2.右键单击Web项目并添加新项目,然后添加启用了Silverlight的Wcf服务".
3.在wcf服务中,添加您要访问数据库的方法.
4.与您在后台代码中的操作方式相同.在Silverlight中,您无法直接访问数据库.您只能通过服务访问数据库.
5.将服务引用添加到您的silverlight项目.右键单击该引用,然后单击添加服务引用",然后选择您创建的wcf服务并为其命名.
6.现在转到您的代码隐藏区或您要访问数据库的位置.
7.为您引用的服务创建一个客户端.
那么使用客户端,您将获得在wcf服务中创建的每个方法的异步方法.

例如:-如果您在WCF服务中创建了"GetEmployees"方法,则在使用服务客户端后的代码中,您将获得一个名为GetEmployeesAsync的名称,通过该名称可以访问WCF服务中的方法,并且可以从服务访问数据库. />
8.与使用oldb名称空间的方法相同.其余与往常相同.

要通过屏幕进一步清除方法,请访问此博客:
http://swayingtheworld.blogspot.com/2011/08/accessing-databases-in-silverlight.html
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


看起来很可能,而且也非常容易...
要访问MS ACCESS,您需要添加此命名空间"system.data.oledb".
但是此名称空间将无法在您的Silverlight应用程序中使用.此名称空间仅在Web项目中可用,即您正在使用的WCF服务...

我会在这里写一个示例代码.但是只要遵循它的逻辑即可!
这是在wcf服务中..ok?
右键单击该Web项目,然后添加名为启用Silverlightlight的Wcf服务"的新项目,并将其命名为SampleService.然后是这样的事情...

使用系统;
使用System.Data.SqlClient;
使用System.Data;

命名空间TimeManagement.Web
{
[DataContract]
公共类雇员
{
[DataMember(Order = 0)]
公用字符串EmployeeID {get;放; }
[DataMember(Order = 1)]
公共字符串FirstName {get;放; }
[DataMember(Order = 2)]
公共字符串LastName {get;放; }
[DataMember(Order = 3)]
公共字符串EmailAddress {get;放; }
}
[ServiceContract(Namespace =&&")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
公共类SampleService
{
[OperationContract]
public int InsertEmployee(字符串的名字,字符串的名字,字符串的EmployeeId,字符串的电子邮件)
{
//做您的字符串连接
//并将数据插入到ur msaccess表中.
//它几乎与您用于连接sql的方式相同.
//由于返回的整数使用executenonquery返回ur值.
}
}

现在在您的Silverlight应用程序中..在参考中单击鼠标右键,添加新的服务参考,并将其命名为sampleserviceRef ...
现在转到您要在其中插入您的数据以访问数据库的页面,然后执行以下操作...

公共无效InsertEmployee(字符串名字,字符串姓氏,字符串EmployeeId,字符串电子邮件)
{
//为服务创建客户端
var SerObj = new SampleServiceRef.TMServiceClient();
SerObj.InsertEmployeeAsync(Firstname,Lastname,EmployeeId,Email);
}

多数民众赞成在插入值...
您无法在Silverlight中直接与数据库通信,因为Silverlight是客户端应用程序..u只能通过WCF服务与数据库通信! 如果您仍然听不懂,请告诉我您的问题.让我解释一下!!!
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!!!


这篇关于如何在silverlightapplicatipon中连接MS Access数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆