——此文章摘自《ASP
NET网络数据库开发实例精解》定价
¥
特价
¥
详细>>http://track
linktech
cn/?m_id=dangdang&a_id=A
&l=
&l_type
=
width=
height=
border=
nosave>
private void Page_Load(object sender SystemEventArgs e)
{
if(!PageIsPostBack)
{
ShowDBData(); //显示数据库MyFirstAccessDB中的数据
}
}
private void ShowDBData()
{ //设在访问数据库的连接字符串
string accessString = ACCESSCONNECTIONSTRING
+ ServerMapPath(MyFirstAccessDBmdb);
string cmdText = SELECT * FROM MyDataTable; //创建获取数据的SQL语句
//创建数据库的连接和Command
OleDbConnection accessConn = new OleDbConnection(accessString);
OleDbCommand accessComm = new OleDbCommand(cmdTextaccessConn);
//定义数据显示的格式
string dataString = <br>MyID MyName MyType My Length<br>;
try
{ //打开OLEDB数据库的连接
accessConnOpen();
ResponseWrite(连接MyFirstAccessDB数据源成功!!!);
//显示数据库中的信息
OleDbDataReader reca = accessCommExecuteReader();
while(recaRead())
{ //获取相应数据
dataString += reca[MyID]ToString() +
+ reca[MyName]ToString()
+ + reca[MyType]ToString() +
+ reca[MyLength]ToString();
dataString += <br>;
}
recaClose();
ResponseWrite(dataString); //显示数据库中的内容
accessConnClose(); //关闭OLEDB数据库的连接
}
catch(Exception ex)
{
ResponseWrite(exMessage); //抛出数据库连接异常
}
}
设置页面ShowDataaspx为应用程序的起始页面按F键运行后出现如图所示的初始界面
right>[http://developcsaicn/dotnet_ASP/htm>] []