您的位置:知识库 » .NET技术

ADO.NET Data Service

作者: WXWinter(冬)  来源: 博客园  发布时间: 2008-12-16 00:01  阅读: 13449 次  推荐: 0   原文链接   [收藏]  
摘要:ADO.NET Data Service介绍
[1] 1.创建DataService项目
[2] 2.添加ADO.NET数据服务
[3] 3.NET客启访问DataService
[4] 4.Silverlight客启访问DataService
[5] 5.URL访问
[6] 6.WEB方法

 

NET客启访问DataService

引用数据服务

 

查询

//查询

private void button1_Click(object sender, EventArgs e)

{

Uri url = new Uri("http://localhost:1468/myWebDataService.svc");

myService.myDBEntities server = new WinFormClient.myService.myDBEntities(url);

 

foreach (var v in server.tabA)

{

 

Console.WriteLine("{0},{1},{2}", v.a, v.b, v.c);

}

//-

foreach (var v in server.tabX.Where(p=>p.x=="002"))

{

 

Console.WriteLine("{0},{1},{2}", v.x, v.y, v.z);

}

 

}

 

lzm ,2 ,5

wxd ,1 ,4

wxwinter ,3 ,6

002 ,8 ,llzzmm

添加

//添加

private void button2_Click(object sender, EventArgs e)

{

Uri url = new Uri("http://localhost:1468/myWebDataService.svc");

myService.myDBEntities server = new WinFormClient.myService.myDBEntities(url);

 

server.AddTotabA(new myService.tabA() { a = "wxdlzm", b = "333", c = "xxx" });

 

server.SaveChanges();

}

 

修改

//修改

private void button3_Click(object sender, EventArgs e)

{

Uri url = new Uri("http://localhost:1468/myWebDataService.svc");

myService.myDBEntities server = new WinFormClient.myService.myDBEntities(url);

var v = server.tabA.Where(p => p.a == "wxdlzm").First();

v.b = "hello";

server.UpdateObject(v);

server.SaveChanges();

}

 

 

删除

//删除

private void button4_Click(object sender, EventArgs e)

{

Uri url = new Uri("http://localhost:1468/myWebDataService.svc");

myService.myDBEntities server = new WinFormClient.myService.myDBEntities(url);

var v = server.tabA.Where(p => p.a == "wxdlzm").First();

server.DeleteObject(v);

server.SaveChanges();

}

 

 

异步查询

//异步查询

 

myService.myDBEntities server1;

 

//开始查询

private void button5_Click(object sender, EventArgs e)

{

Uri url = new Uri("http://localhost:1468/myWebDataService.svc");

Uri urlE = new Uri("http://localhost:1468/myWebDataService.svc/tabX");

server1 = new WinFormClient.myService.myDBEntities(url);

 

server1.BeginExecutetabX>(urlE, new AsyncCallback(executed), null);

}

//返回结果

void executed(IAsyncResult obj)

{

var tp = server1.EndExecutetabX>(obj);

 

foreach (var v in tp)

{

Console.WriteLine("{0},{1},{2}", v.x, v.y, v.z);

}

 

}

 

0
0

.NET技术热门文章

    .NET技术最新文章

      最新新闻

        热门新闻