程序没有错,能正常运行。怎么优化?

kellybs 2003-10-17 02:33:13
程序代码:
<%@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>
...全文
35 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
kellybs 2003-10-17
  • 打赏
  • 举报
回复
代码太多了,应该是写一个函数,然后调用他
guoyan19811021 2003-10-17
  • 打赏
  • 举报
回复
你想怎么优化?
其实SqlClient就已经对Sql Server优化了
gshope 2003-10-17
  • 打赏
  • 举报
回复
这么简单的代码也没什么优化的余地了,唯一的,用一个SqlDataAdapter就可以了,为什么还用了三个呢!

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧