惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Palo Alto Networks Blog
D
Docker
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Schneier on Security
Engineering at Meta
Engineering at Meta
I
InfoQ
L
LangChain Blog
Cyberwarzone
Cyberwarzone
T
Tenable Blog
WordPress大学
WordPress大学
P
Privacy & Cybersecurity Law Blog
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Jina AI
Jina AI
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
Know Your Adversary
Know Your Adversary
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Last Watchdog
The Last Watchdog
Last Week in AI
Last Week in AI
Cloudbric
Cloudbric
S
SegmentFault 最新的问题
爱范儿
爱范儿
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
AI
AI
T
Tor Project blog
I
Intezer
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
N
News and Events Feed by Topic
Latest news
Latest news
S
Security Affairs
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog RSS Feed
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
S
Securelist

博客园 - greater

Matlab 7.0不断重启问题解决方法 安装Matlab过程中遇到拒绝访问怎么办? NUnit图解(一) [翻译]Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition 第二十四章 LINQ API编程(三) [翻译]Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition 第二十四章 LINQ API编程(二) [翻译]Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition 第二十四章 LINQ API编程(一) 迷人舞步 难译的英文单词 Linq 之Expression Tree再思考 VS2008代码段快捷方式小记 Linq To SQL分页失败后引发的思考 Linq之查询非泛型集合 函数式编程的浅议 Linq操作符之筛选特定位置的元素 Linq与斐波那契数列共舞 Linq的那些事——从Linq扩展方法回顾C#语言基础 Linq To Object实例之过滤字符集 Linq之C#3.0语言扩展 从101 LINQ Samples开始
Linq to DataSet 之Access查询
greater · 2008-05-31 · via 博客园 - greater

  Linq核心的组成部分有LINQ to SQL, LINQ to DataSet, LINQ to Entities和LINQ to XML,根据Linq对于其他的集成很快会由微软或第三方实现,而改技术对于Access数据库的支持并没有像SQL Server那么友好,今天尝试用Linq查询Access数据文件时遇到了不少麻烦,在网上搜索后发现很多朋友都遇到了相同的问题,经过反复的尝试,终于初步完成了Access的查询。

下面是实现步骤:

1.准备: 用Access2007建立一个users.mdb文件,里面定义一个users表包括了以下三个字段——ID(int),Name(文本),Password(文本)。

2.新建一个控制台程序后,导入改数据连接,VS2008会自动的生成与数据表对应的强类型数据集并且完成相应的配置文件,其中关键的配置代码如下:
......

    <connectionStrings>
        <add name="Chp.Properties.Settings.usersConnectionString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\users.accdb;Persist Security Info=True"
            providerName="System.Data.OleDb" />
    </connectionStrings>

......
3.实现代码
            //定义相关的DataSet和TableAdapter
            usersDataSet uDS = new usersDataSet();
            usersTableAdapter uTA = new usersTableAdapter();
            usersDataSet.usersDataTable uTable = new usersDataSet.usersDataTable();
        uTA.ClearBeforeFill=true;
            uTA.Fill(uTable);
            ......
            //通过LinQ查询users表中用户名为需要查询的信息,这里AsEnumerable()是必须的
            //而u.Field<string>("Name")=="......"的意思是判断是否为需要查询的类型为string的Name字段
            var users = (from u in uTable.AsEnumerable()
                             where u.Field<string>("Name")=="......"
                             select u).First();
            ......
            //打印查询到的Password
            Console.WriteLine("Password:{0}", users.Field<string>("Password") );

总结:其实这里的Linq查询Access主要还是通过LINQ to DataSet实现和完成的,但是从实现方式上又是按照了ORM的模式来执行的,不得不说的是Linq为数据的查询提供了极大的便利,同时也简化了数据的操作,开始明白微软为解决Data!=Object的意图了!