我最近问了一个关于如何写查询的问题,谢天谢地你们回答了我(谢谢)
我在一个 WML 站点上工作,所以我需要从查询中传递值我找到了一种方法(如下代码所示),但它没有用。
<%
//this Query was provided earlier in the previous question.
string queryString = "select st.firstname + ' ' + st.lastname,se.year, c.coursename,c.NumberOfCredits,ri.mark from Students st inner join RegisteredIn ri on ri.StudentId=st.id inner join Semester se on se.id=ri.SemesterId inner join Courses c on c.id=se.id ";
我找到但没有工作的方式
using (System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(connectionString))
{
System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(queryString, connection);
command.Parameters.AddWithValue("@StudentId",StudentId);
connection.Open();
System.Data.SqlClient.SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
string _firstname = reader[0].ToString();
string _lastname = reader[1].ToString();
string _coursename = reader[2].ToString();
string _credits = reader[3].ToString();
string _mark = reader[4].ToString();
string url = string.Format("~/StudentInfo.aspx?StudentId={0}&firstname={1}&lastname={2}&coursename={3}&credits={4}&mark={5}", StudentId, _firstname, _lastname, _coursename, _credits, _mark);
Response.Redirect(url);
%>
接收参数的页面将类似于
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="StudentInfo.aspx.cs" Inherits="StudentInfo" %>
<wml>
<card>
<p><% Response.Write(Request.Params["StudentId"]);%></p>
<p><b>firstname:</b> <% Response.Write(Request.Params["firstname"]);%></p>
<p><b>lastname:</b> <% Response.Write(Request.Params["lastname"]);%></p>
<p><b>coursename:</b> <% Response.Write(Request.Params["coursename"]);%></p>
<p><b>credits:</b> <% Response.Write(Request.Params["credits"]);%></p>
<p><b>Mark:</b> <% Response.Write(Request.Params["mark"]);%></p>
</card>
</wml>
结果将类似于
First Semester 2010
Student : Arin Rizk
Course Name No. of Credit Mark
AAA 3 65
BBB 3 23
CCC 3 65
DDD 3 58
EEE 3 70
Your GPA for this semster is 3.12
我的问题是: - 如何从查询中提取值并放入 URL 中?- 我将如何在 WML 或 ASP 中显示多个值?(因为结果将是多行和值)
先感谢您