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

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - culturenet

jQuery Mobile 小问题解决一例 flash的传值问题 Oracle 升级以后 HTTP Server 一则小错误解决 installshield安装文件的制作小技巧--附加数据库 使用installshild解决某些安装文件无法在win2003上安装的问题 vsta下vs2005产生错误,解决之 Test Windows Live Write (Bate) Gridview中当设置自动生成列时对列中字段使用 html代码显示 修改ppt另存为网页的mht文件内容,更改其显示方式 修改OleDB provider 移植 Data Application Blocks项目中使用存储过程的应用(Oracle or MsSqlServer)到Microsoft Access Oracle Services For Microsoft Transaction Server的问题的发现与解决 LinkButton 的提交两次问题的解决 Enterprise Library- Data Block使用oracle存储过程,字符串参数传入值为""时出现问题的解决 Enterprise Library - Data Block oracle返回 cursor 问题的解决 web.config中的pageBaseType问题 修改客户端Script,解决r.a.d.controls Q2 2005中TreeView 控件遮挡问题 [导入]汉字区位码查询 [导入]c#取得汉字的拼音的首字母。 [导入]url传递中文的解决方案总结 [导入]转:url传递中文的解决方案总结
Enterprise Library- Data Block 使用MS Access的问题的解决
culturenet · 2005-10-11 · via 博客园 - culturenet

因为项目中一直使用Enterprise Library- Data Block oralce作服务器端的应用。现在要做一个桌面的应用。为了统一,也准备使用 Enterprise Library- Data Block 来做 MS Access 。于是就上网找了 Enterprise Library的Oledb的源代码,回来自己手动编译生成 dll 。

/Files/culturenet/OleDbData.zip

配置以后,使用代码如下:

Database db = DatabaseFactory.CreateDatabase("AccessDb");
    
string sqlCommand = "SELECT * FROM MYRESOURCE";
    DBCommandWrapper dbCommandWrapper 
=db.GetStoredProcCommandWrapper(sqlCommand);
       DataSet ds
=db.ExecuteDataSet(dbCommandWrapper);
    dataGrid1.DataSource
=ds.Tables[0];

使用中发生异常。
跟踪发现,原来是 传入 的 Command 的 CommandType 为 StoredProcedure 造成的。

于是乎就有两种做法来避免异常:

1、在Access中用 SELECT * FROM MYRESOURCE  建立一个查询,名字为:SOURCE

使用代码为:

    Database db = DatabaseFactory.CreateDatabase("AccessDb");
                
string sqlCommand = "SOURCE";
                DBCommandWrapper dbCommandWrapper 
=db.GetStoredProcCommandWrapper(sqlCommand);
                DataSet ds
=db.ExecuteDataSet(dbCommandWrapper);
                dataGrid1.DataSource
=ds.Tables[0];

2、直接在代码中指定 CommandType 为 text

代码如下:

    Database db = DatabaseFactory.CreateDatabase("AccessDb");
                
string sqlCommand = "SELECT * FROM MYRESOURCE";
                DBCommandWrapper dbCommandWrapper 
=db.GetStoredProcCommandWrapper(sqlCommand);
                dbCommandWrapper.Command.CommandType
=CommandType.Text;
                DataSet ds
=db.ExecuteDataSet(dbCommandWrapper);
                dataGrid1.DataSource
=ds.Tables[0];


呵呵,今天早上忽然记起来,可以使用 GetSqlStringCommandWrapper 方法来代替 GetStoredProcCommandWrapper,就不用设置CommandType了。昨天晚上肯定是晕了,以前经常用的方法都给忘了。