会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
Billpeng Space
技术源自生活
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
公告
使用OleDbDataReader 或sqldatareader 连数据库
Posted on
2008-11-10 19:54
billpeng
阅读(
414
) 评论(
0
)
编辑
收藏
举报
<%
@ Page Language
=
"
C#
"
Debug
=
"
true
"
%>
<%
@Import NameSpace
=
"
System.Data
"
%>
<%
@Import NameSpace
=
"
System.Data.OleDb
"
%>
<%
string
StrCon
=
"
Provider=Microsoft.Jet.OleDb.4.0;Data Source=
"
+
Server.MapPath(
"
data.mdb
"
);
//
建立数据库连接串,此处为OLEDB连接方式,另外还有ado连接方式
string
strSQL
=
"
SELECT * FROM main order by 编号 desc
"
;
//
sql查询,查找所有新闻记录,把它们按编号降序排序.
OleDbConnection MyConnection
=
new
OleDbConnection(StrCon);
//
建立OLEDB connection连接对象
OleDbCommand myCommand
=
new
OleDbCommand(strSQL,MyConnection);
//
建立OLEDB command连接对象
OleDbDataReader myDataReader
=
null
;
//
建立数据读取对象
myCommand.Connection.Open();
//
打开connection连接
myDataReader
=
myCommand.ExecuteReader();
//
为数据读取对象建立数据源
myDataReader.Read();
//
开始读取数据源
Response.Write(
"
dnews=
"
+
myDataReader[
"
新闻
"
].ToString());
//
新闻输出,格式: dnew=新闻内容 &dtime=更新时间
Response.Write(
"
&dtime=
"
+
myDataReader[
"
更新时间
"
].ToString());
myCommand.Connection.Close();
//
关闭connection连接
%>
刷新页面
返回顶部
Powered by:
博客园
Copyright © 2025 billpeng
Powered by .NET 9.0 on Kubernetes