如何在C#中编写此代码 [英] How to write this code in c#

查看:102
本文介绍了如何在C#中编写此代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是经典的ASP代码,我想在ASP.NET C#中编写此代码.请任何人帮我.

This is a classic asp code, i want to write this code in asp.net c#. Please any one help me.

<%
response.buffer=false
id=killchars(request.querystring("id"))



    Response.ContentType = "text/xml"
    set con = server.CreateObject("adodb.connection")
    con.open strCon


    set rs=Server.CreateObject("ADODB.Recordset")
    sqltxt="SELECT top 12 id,title FROM table1 where status=1 and not id="&id&" and admin_no is NULL order by sticky desc,date desc"
    'response.write sqltxt
    rs.open sqltxt,con,0,1



    Response.Write "<?xml version=""1.0"" encoding=""iso-8859-1"" ?>" & vbCrlf
    Response.Write "<rss version=""2.0"">" & vbCrlf
    Response.Write "<channel>" & vbCrlf
    Response.Write "<title>Recent results</title>" & vbCrlf

    Do while Not rs.eof


    Response.Write "<item>" & vbCrlf
    Response.Write "<title>" & encode(rs("title")) &"</title>" & vbCrlf
    Response.Write "<link>http://localhost/news/"&cleanstring(rs("title"))&"-"&rs("id")&".asp</link>" & vbCrlf
    'Response.Write "<price>" & rs("sb_price")&"</price>" & vbCrlf
    'Response.Write "<description>"  & vbCrlf
    'Response.Write "<![CDATA[" & vbCrlf
    'Response.Write left(replace(rs("sb_details"),"&","and"),100)& "...]]>" & vbCrlf
    'Response.Write "</description>" & vbCrlf
    Response.Write "</item>" & vbCrlf

    rs.MoveNext
    Loop
    Response.Write "</channel>" & vbCrlf
    Response.Write "</rss>" & vbCrlf

    rs.Close
    set rs = nothing
    con.Close
    set con= nothing

%>




在此先感谢

我只想知道执行此操作的最佳过程是什么?




Thanks in advance

I just want to know what is the best procedure to do that

推荐答案

好吧,您将忽略所有这些可怕的代码,然后重新开始.在ASP.NET中,您可以使用诸如gridview之类的控件,或者,如果需要此级别的控件,则可以使用中继器.您通过数据层获取数据,然后将其绑定到网格.如果要发送XML,则在服务器上创建XML(最好的方法是从SQL Server IMO请求XML)并发送.
Well, you would ignore all this horrible code and start again. In ASP.NET you use a control like a gridview or, if you want this level of control, a repeater. You get your data through a data layer, and then bind it to a grid. If you want to send XML, then you create it on the server ( best way is to request XML from SQL Server IMO ) and send that.


您需要首先学习ASP.NET.
http://msdn.microsoft.com/en-us/library/ms123401.aspx [ ^ ]

http://www.asp.net/ [ ^ ]

谢谢,
马蒙
You need to learn ASP.NET first.
http://msdn.microsoft.com/en-us/library/ms123401.aspx[^]

http://www.asp.net/[^]

Thanks,
Mamun


这篇关于如何在C#中编写此代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆