程序没有错,能正常运行。怎么优化?
程序代码:
<%@Page Language="c#"%>
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.SqlClient"%>
<script language="C#" runat="server">
void Page_Load()
{
//每个记录集的newsid参数不同,该如何优化,请在原代码上修改,谢谢!
string strConnection="Password=icncn1218;User ID=sa;Initial Catalog=icncn;Data Source=localhost;";
SqlConnection myConnection=new SqlConnection(strConnection);
SqlDataAdapter myCommand = new SqlDataAdapter("select top 10 id,subject from changnews where newsid='27' order by id desc", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "changnews");
MyRepeater.DataSource = ds.Tables["changnews"].DefaultView;
MyRepeater.DataBind();
SqlDataAdapter myCommand1 = new SqlDataAdapter("select top 10 id,subject from changnews where newsid='28' order by id desc", myConnection);
DataSet ds1 = new DataSet();
myCommand1.Fill(ds1, "changnews");
MyRepeater1.DataSource = ds1.Tables["changnews"].DefaultView;
MyRepeater1.DataBind();
SqlDataAdapter myCommand2 = new SqlDataAdapter("select top 10 id,subject from changnews where newsid='29' order by id desc", myConnection);
DataSet ds2 = new DataSet();
myCommand2.Fill(ds2, "changnews");
MyRepeater2.DataSource = ds2.Tables["changnews"].DefaultView;
MyRepeater2.DataBind();
}
</script>
<html>
<head>
<title>欢迎你来到长三角网!!</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<ASP:Repeater id="MyRepeater1" runat="server">
<HeaderTemplate>
<table width="560" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="25" bgcolor="#FFC20E" colspan="2"> <strong><font color="#004684">经济动态</font></strong></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr >
<td align="center"> <img src="/images/point.gif" width="4" height="5"> </td>
<td height="22"><%# DataBinder.Eval(Container.DataItem, "subject")%></td>
</tr>
</ItemTemplate><FooterTemplate>
</table>
</FooterTemplate>
</ASP:Repeater>
<ASP:Repeater id="MyRepeater" runat="server">
<HeaderTemplate>
<table width="560" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="25" bgcolor="#FFC20E" colspan="2"> <strong><font color="#004684">社会热点</font></strong></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr >
<td align="center"> <img src="/images/point.gif" width="4" height="5"> </td>
<td height="22"><%# DataBinder.Eval(Container.DataItem, "subject")%></td>
</tr>
</ItemTemplate><FooterTemplate>
</table>
</FooterTemplate>
</ASP:Repeater>
<ASP:Repeater id="MyRepeater2" runat="server">
<HeaderTemplate>
<table width="560" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="25" bgcolor="#FFC20E" colspan="2"> <strong><font color="#004684">文化聚焦</font></strong></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr >
<td align="center"> <img src="/images/point.gif" width="4" height="5"> </td>
<td height="22"><%# DataBinder.Eval(Container.DataItem, "subject")%></td>
</tr>
</ItemTemplate><FooterTemplate>
</table>
</FooterTemplate>
</ASP:Repeater></body>
</html>