ASP.NET中的列名无效
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 ck_score7 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ck_Click(object sender, EventArgs e)
{
string xh = xuehao.Text.ToString();
string xqi = xq.Text.ToString();
string xni = xn.Text.ToString();
string kmu = km.Text.ToString();
SqlConnection conn = new SqlConnection("server=localhost;database=gydianzi;uid=sa;pwd=123");
conn.Open();
SqlCommand comm = new SqlCommand("select * from scorelist where s_name=xh and s_year=xni and s_term=xqi and s_sort=kmu", conn);
SqlDataReader dr = comm.ExecuteReader();
dr.Read();
xm.Text = dr["s_truename"].ToString();
yjzz.Text = dr["s_score1"].ToString();
cxsj.Text = dr["s_score2"].ToString();
ys.Text = dr["s_score3"].ToString();
zp.Text = dr["s_allscore"].ToString();
xf.Text = dr["s_credithour"].ToString();
}
}
问题:
“/CheckScore”应用程序中的服务器错误。
--------------------------------------------------------------------------------
列名 'xh' 无效。
列名 'xni' 无效。
列名 'xqi' 无效。
列名 'kmu' 无效。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: 列名 'xh' 无效。
列名 'xni' 无效。
列名 'xqi' 无效。
列名 'kmu' 无效。
源错误:
行 26: conn.Open();
行 27: SqlCommand comm = new SqlCommand("select * from scorelist where s_name=xh and s_year=xni and s_term=xqi and s_sort=kmu", conn);
行 28: SqlDataReader dr = comm.ExecuteReader();
行 29: dr.Read();
行 30: xm.Text = dr["s_truename"].ToString();
源文件: f:\Firstproject\CheckScore\ck_score2.aspx.cs 行: 28