我想通过下列代码把数据库的信息显示在已经建立好的单元格中,可是下列程序并不能把我的数据库中的信息显示在单元格,求哪位好心人帮我解答,万分感谢!
<%@ Page Title="主页" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql" %>
<%@ Import Namespace= "System.Data.SqlClient" %>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<div style="height: 251px; width: 704px">
<table cellpadding="0" cellspacing="0" class="body">
<tr>
<td rowspan="2" class="style7">
<asp:Image ID="Image2" runat="server" Height="253px"
ImageUrl="~/Image/Default_content.jpg" Width="213px" />
</td>
<td class="style10">
<table cellpadding="0" cellspacing="0" class="style8" align="left"
style="position:relative;left:3px; top:-53px;">
<tr>
<td colspan="3" class="style9"
style="background-image: url('http://localhost:6556/Persevere/Image/mainNewsBg.jpg'); text-align: justify;">
<a href="NewPage.aspx" class="aaa" >公司新闻</a></td>
</tr>
<%
string connstr = ConfigurationManager.ConnectionStrings["PersevereConnectionString2"].ToString();
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
string sqlstr = "SELECT * FROM New ORDER BY ID DESC";
SqlCommand cmd = new SqlCommand(sqlstr, conn);
SqlDataReader sdr = null;
sdr = cmd.ExecuteReader();
int i = 1;
int total = 9;
while (sdr.Read() && i < total)
{
%>
<tr>
<td>
<a href="NewPage.aspx?id=<% = sdr["ID"].ToString() %>" target="_blank"></a></td>
<td>
<a href="NewPage.aspx?id=<% = sdr["Title"].ToString() %>" target="_blank"></a></td>
<td>
<a href="NewPage.aspx?id=<% = sdr["Contents"].ToString() %>" target="_blank"></a></td>
</tr>
<%
i++;
}
sdr.Dispose();
sdr.Close();
%>
</table>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</div>
</asp:Content>