C#显示数据库记录
<%@Page language="C#" Debug="True"%>
<% @ Import Namespace="System.Data"%>
<% @ Import Namespace="System.Data.OleDb"%>
<html>
<head>
<title>新闻发布系统</title>
<style type="text/css">
<!--
TABLE { FONT-SIZE: 9pt }
INPUT { FONT-SIZE: 9pt }
SELECT{ FONT-SIZE: 9pt }
BODY { FONT-SIZE: 9pt }
a:link { color: #000099; text-decoration: none}
a:visited { color:#000099; text-decoration: none}
a:hover { color: #990000; text-decoration: underline}
td {font-size:9pt;line-height:13pt;}
.p1 { font-family: "宋体"; font-size: 9pt}
.p2 { }
.p3 { font-family: "宋体"; font-size: 12pt}
-->
</style>
<script Language="C#" runat="server">
String newsid;
void Page_Load(Object sender,EventArgs e)
{
String ConnStr,strCon;
newsid = Request.QueryString["id"];
string db=@"mydb.mdb";
string conncjr="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source="+Server.MapPath(db)+";";
OleDbConnection Conn=new OleDbConnection(conncjr);
Conn.Open();
String strCom= "SELECT biaoti ,zhaizi ,neirong,img,counter ,shijian FROM [news] where id="+newsid;
OleDbDataAdapter myCommand=new OleDbDataAdapter(strCom,conncjr);
DataSet ds= new DataSet();
myCommand.Fill(ds,"news");
DataRow dr=ds.Tables["news"].Rows[0];
strCon ="SELECT n FROM news WHERE id = "+newsid;
OleDbCommand myCommand2= new OleDbCommand(strCon,Conn);
OleDbDataReader reader = myCommand2.ExecuteReader();
reader.Read();
int i = reader.GetInt32(0);
i++;
reader.Close();
strCon ="UPDATE news SET n = "+i.ToString()+" WHERE (id= "+newsid+")";
myCommand2.CommandText = strCon;
myCommand2.ExecuteNonQuery();
Conn.Close();
}
</script>
</head>
<body bgcolor="#FFFFFF" link="#000000">
<div align="center" class="p2">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center">新闻发布系统</div></td>
</tr>
<tr><td> </td>
</tr>
</table>
<table width="500" border="1" cellspacing="0" cellpadding="0" bordercolordark="#FFFFFF" bordercolorlight="#CCCCCC">
<tr>
<td background="mmto.gif" height="15" width="470">
<table width="500" border="0" cellspacing="0" cellpadding="0" background="mmto.gif">
<tr>
<td background="mmto.gif"> </td>
<td background="mmto.gif">
<div align="right">
<img src="printer.gif" width="16" height="14">
<a href="javascript:window.print()">打印本页</a>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="470">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td class="p3"><br><%=dr["biaoti"]%></td>
</tr>
<tr align="center">
<td> <div> <hr size="1" width="300">
<font color="#999999">[<%=dr["shijian"]%>]</font><br>
</div>
</td>
</tr>
<tr>
<td>
<%
if(dr["img"] != "") {
Response.Write("<img src=‘" + dr["img"] + "‘ border=0 align=‘left‘ width=‘20‘ height=‘200‘>");
}
%><br> <%=dr["neirong"]%>
</td>
</tr>
<tr>
<td> <br>
<br> 摘自: <%=dr["zhaizi"]%>
<br>
</td>
</tr>
<tr>
<td>
<div align="right"></div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="17">
<table width="498" border="0" cellspacing="0" cellpadding="0" mmto.gif">
<tr>
<td width="172" background="mmto.gif">本条消息被浏览了
<font color="#FF3333">[<%=dr["Counter"]%>]</font>回
</td>
<td width="172" background="mmto.gif">
</td>
<td width="134" background="mmto.gif">
<p align="right"><a href="javascript:window.close()">关闭本窗口 </a></p>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="bian.gif" width="500" height="13"></td>
</tr>
</table>
</div>
</body>
</html>
想问各个大虾一下我在上面中使用DataRow对象有没有错
如果没错那么要怎么显示单条记录呢