Silverlight与Access数据库的互操作.pdf
文本预览下载声明
Silverlight 与Access 数据库的互操作(CURD 完全解析)
Silverlight 与SQL Server 或SQL Server Express 的互操作,已成为我们常见的开发Siverlight 应
用程序的一种模式。可是在开发一些小型应用程序时,我们就需要使用一些小巧的轻量级的数据
库,比如Access 数据库。由于Visual Studio 中并没有直接提供Silverlight 与Access 互操作的系
列方法。于是本文就将为大家介绍如何让Silverlight 使用Access 作为后台数据库。
准备工作
1)建立起测试项目
细节详情请见强大的DataGrid 组件[2]_数据交互之ADO.NET Entity Framework——Silverligh
t 学习笔记[10]。
2)创建测试用数据库
如下图所示,创建一个名为Employees.mdb 的Access 数据库,建立数据表名称为Employee 。将
该数据库置于作为服务端的项目文件夹下的App_Data 文件夹中,便于操作管理。
建立数据模型
EmployeeModel.cs 文件(放置在服务端项目文件夹下)
using System;
using System.Collections.Generic;
using System.Linq;
namespace datagridnaccessdb
{
public class EmployeeModel
{
public int EmployeeID { get; set; }
public string EmployeeName { get; set; }
public int EmployeeAge { get; set; }
}
}
建立服务端Web Service★
右击服务端项目文件夹,选择Add-New Item ,按下图所示建立一个名为EmployeesInfoWeb
Service.asmx 的Web Service ,作为Silverlight 与Access 数据库互操作的桥梁。
创建完毕后,双击EmployeesInfoWebService.asmx 打开该文件。将里面的内容修改如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.OleDb;//引入该命名空间为了操作Access 数据库
using System.Data;
namespace datagridnaccessdb
{
/// summary
/// Summary description for EmployeesInfoWebService
/// /summary
[WebService (Namespace = /)]
[WebServiceBinding (ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem (false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX,
uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class EmployeesInfoWebService : System.Web.Services.WebService
{
[WebMethod]//获取雇员信息
public ListEmployeeModel GetEmployeesInfo()
{
ListEmployeeMod
显示全部