我是一个爱好程序员,直到最近才使用 ASP 经典。我正在使用 Razor 语法并尝试从 ASP Classic 复制一些代码。
我一直在使用的 w3schools 的 asp 经典代码如下
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
set rs = Server.CreateObject("ADODB.recordset")
sql="SELECT Companyname, Contactname FROM Customers"
rs.Open sql, conn
%>
<table border="1" width="100%">
<tr>
<%for each x in rs.Fields
response.write("<th>" & x.name & "</th>")
next%>
</tr>
<%do until rs.EOF%>
<tr>
<%for each x in rs.Fields%>
<td><%Response.Write(x.value)%></td>
<%next
rs.MoveNext%>
</tr>
<%loop
rs.close
conn.close
%>
</table>
我知道大多数人会说使用 webgrid。是的,我已经这样做了,它真的很慢,所以我试图通过将其与此进行比较来解决它。我在剃须刀中的代码如下
var SelectCommand1 = "DECLARE @cols AS NVARCHAR(MAX), @query AS NVARCHAR(MAX); " +
"SET @cols = STUFF((SELECT ',' + QUOTENAME(tblTests.Name ) " +
"FROM tblTestsInEvents c INNER JOIN tblTests ON c.Test_ID = tblTests.Test_ID " +
"WHERE c.Event_ID = @0 order by c.TestsInEvents_ID FOR XML PATH(''), TYPE ).value('.', 'NVARCHAR(MAX)') ,1,1,'') " +
"set @query = 'SELECT Car_Number, First_Name, Last_Name, ' + @cols + ' " +
"from ( select First_Name, Last_Name, tblTestsLog.Driver_ID, Name, CorrectedTime, tblDriversInEvents.Car_Number "+
"FROM tblTests INNER JOIN "+
"tblTestsLog ON tblTests.Test_ID = tblTestsLog.Test_ID INNER JOIN "+
"UserProfile ON tblTestsLog.Driver_ID = UserProfile.UserId INNER JOIN "+
"tblDriversInEvents ON UserProfile.UserId = tblDriversInEvents.Driver_ID AND tblTestsLog.Event_ID = tblDriversInEvents.Event_ID) "+
"x pivot ( sum(CorrectedTime) for Name in (' + @cols + ') ) p ' "+
"execute(@query)";
var SelectedData1 = db.Query(SelectCommand1, EventID);
内联代码是这样的:
@{//grid.GetHtml()
<text><table></text>
foreach (var x in SelectedData1)
{
@:<tr>
foreach (var y in x.Fields)
{
<text><td>@y.value</td></text>
}
@:</tr>
}
}
</table>
x.Fields 目前正在失败,我找不到等价物。任何建议和提示都会很棒。谢谢