标题:C#显示数据库记录
只看楼主
cjrboy
Rank: 1
等 级:新手上路
帖 子:141
专家分:0
注 册:2004-11-30
 问题点数:0 回复次数:1 
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对象有没有错 如果没错那么要怎么显示单条记录呢
搜索更多相关主题的帖子: 数据库 Import none title 
2005-08-07 16:02
virusswb
Rank: 1
等 级:新手上路
威 望:1
帖 子:342
专家分:0
注 册:2005-8-6
得分:0 
你在代码i++处应该写个循环,试试

jorden008@
2005-08-07 16:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-24580-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.063204 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved