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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - yueue

Ext Portal如何消除横向滚动条 JavaScript中的对象动态加载技术 JavaScript使用ACTIVEX控件引起崩溃问题的解决 如何把Ext.data.store里的数据一次性用JSON传给后台(添加了后台解析部分) - yueue 解决EXT DateField 用getValue() 发送到后台,后台取null的问题 - yueue 如何使开启了分页功能的EXT Combox可以自动选中非第一页的值 ExtJs 中一个Toolbar 不够用?再来一个! - yueue 为什么ext combox 下拉框不出现自动提示,自动选中 如何做一个两列的FormPanel json-lib出现There is a cycle in the hierarchy解决办法 EXT如何把一个对象转换为JSON并将其发送到服务器 - yueue - 博客园 ExtJs如何通过JSON与后台通信 ExtJs 及 Ajax 乱码解决方案 - yueue [教程]创建ADOKeycap数据库对象 认识 yueue.ADOKeycap 开源数据库组件 [教程]使用yueueData统计数据 [教程]使用ADOKeycap插入,更新,删除数据 [教程]使用AODKeycap读取数据 - yueue [教程]添加yueue.ADOKeycap数据库组件到您的项目 - yueue - 博客园
[教程]在ADOKeycap中使用DataReader读取数据
yueue · 2007-05-13 · via 博客园 - yueue

注意

您在阅读本教程前最好先阅读
http://www.cnblogs.com/yueue/archive/2007/05/13/744578.html<将ADOKeycap添加到您的项目>
http://www.cnblogs.com/yueue/archive/2007/05/26/760641.html<创建ADOKeycap数据库对象>
使用Reader最后切记关闭连接,因为Reader跟DataSet的区别在于DataSet是一次性截入内存然后立即可关闭数据库,而Reader在使用过程中一直连接着数据库.

请注意引用:

using System.Data.Common;
using yueue.ADOKeycap;

此处 Database db1 = DatabaseManager.CreateDatabase("ms1"); 只为教学,实际开发中建议创建全局 Database 对象普通读取

  • 读取"ms1"数据库中book表的所有内容
    Database db1 = DatabaseManager.CreateDatabase("ms1");
    DbDataReader dr = db1.ExecuteReader("select * from book");
    while (dr.Read())
    {
        Label1.Text += dr["字段1"].ToString() + "</br>" ;
    }
    dr.Close(); //关闭连接

参数化读取

  • 读取"ms1"数据库book表中价格为20的记录,并将第4个字段显示出来
    Database db1 = DatabaseManager.CreateDatabase("ms1");
    db1.AddParameter("@p1",20);
    DbDataReader dr = db1.ExecuteReader("select * from book where 价格=@p1");
    while (dr.Read())
    {
        Label1.Text += dr[3].ToString() + "</br>";
    }
    dr.Close();

储存过程读取

  • 用储存过程UserInfo读取"ms1"数据库,需要参数@id
    Database db1 = DatabaseManager.CreateDatabase("ms1");
    db1.AddParameter("@id",1);
    DbDataReader dr = db1.ExecuteReader("UserInfo");
    while (dr.Read())
    {
        Label1.Text += dr[1].ToString() + "</br>"
    }
    dr.Close();