我是一个新手,原来是做CS的,现在有个需要就是在某个网页上输入一个条件然后查询后返回一个值,举例如下:
查询某个学生的成绩,我在一个网页上输入该学生学号,则返回该学生成绩,请问这个成绩如何获得?最好有个实例,谢谢大家!

解决方案 »

  1.   

     页面
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="txtID" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /><br />
            <asp:Label ID="lblName" runat="server" Text="Label"></asp:Label></div>
        </form>
    </body>
    </html>
    后台
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {    }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string connectionString = "Data Source=.;database=Northwind;uid=sa;pwd=sa";
            SqlConnection con = new SqlConnection(connectionString);
            con.Open();
            string sql="select * from bb where id="+txtID.Text;
            SqlCommand com = new SqlCommand(sql, con);
            SqlDataReader dr = com.ExecuteReader();
            
            while (dr.Read())
            {
                this.lblName.Text = dr["jh"].ToString();
            }
            dr.Close();
        }
    }
    简单写了一个没有用三层!!
      

  2.   

    this.textBox.text
    Or
    this.DropdownList.selectValue
    or
     ...............