<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQL" %> <html>
<head> <script language="C#" runat="server">
public SQLDataReader myReader;
public String html; protected void Page_Load(Object Src, EventArgs E ) {
SQLConnection mySQLConnection = new SQLConnection("server=localhost;uid=sa;pwd=;database=northwind");
SQLCommand mySQLCommand = new SQLCommand("select * from customers", mySQLConnection); try {
mySQLConnection.Open();
mySQLCommd.Execute(out myReader); html="<Table>";
html+="<TR>";
html+="<TD><B>Customer ID</B> </TD>";
html+="<TD><B>Company Name</B></TD>";
html+="</TR>"; while (myReader.Read()) {
html+="<TR>";
html+="<TD + myReader["CustomerID"].ToString() + "</TD>";
+ myReader["CustomerID"].ToString() + "</TD>";
html+="<TD>" + myReader["CompanyName"].ToString() + "</TD>";
html+="</TR>";
}
html+="</Table>";
}
catch(Exception e) {
html=e.ToString();
}
finall y {
meader.Close();
ader.Close();
mySQLConnection.Close();
}
Response.Write(html);
}
</script>
</head> <body> </body>
</html>问题:在while循环中,为什么没有控制下一条(通过while循环)记录的操作,给我的
感觉像是一下子将表中的记录全部按原表中的顺序显示出来。仅仅是一个
myReader["CustomerID"].ToString() 就能将记录集中的customerid显示完?(怎么不像
如vb中的next呢)
<%@ Import Namespace="System.Data.SQL" %> <html>
<head> <script language="C#" runat="server">
public SQLDataReader myReader;
public String html; protected void Page_Load(Object Src, EventArgs E ) {
SQLConnection mySQLConnection = new SQLConnection("server=localhost;uid=sa;pwd=;database=northwind");
SQLCommand mySQLCommand = new SQLCommand("select * from customers", mySQLConnection); try {
mySQLConnection.Open();
mySQLCommd.Execute(out myReader); html="<Table>";
html+="<TR>";
html+="<TD><B>Customer ID</B> </TD>";
html+="<TD><B>Company Name</B></TD>";
html+="</TR>"; while (myReader.Read()) {
html+="<TR>";
html+="<TD + myReader["CustomerID"].ToString() + "</TD>";
+ myReader["CustomerID"].ToString() + "</TD>";
html+="<TD>" + myReader["CompanyName"].ToString() + "</TD>";
html+="</TR>";
}
html+="</Table>";
}
catch(Exception e) {
html=e.ToString();
}
finall y {
meader.Close();
ader.Close();
mySQLConnection.Close();
}
Response.Write(html);
}
</script>
</head> <body> </body>
</html>问题:在while循环中,为什么没有控制下一条(通过while循环)记录的操作,给我的
感觉像是一下子将表中的记录全部按原表中的顺序显示出来。仅仅是一个
myReader["CustomerID"].ToString() 就能将记录集中的customerid显示完?(怎么不像
如vb中的next呢)
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货