【发布时间】:2014-05-23 15:05:01
【问题描述】:
我使用上传文件的人的用户名更新数据库,并尝试仅检索当前用户上传的文件,以显示在 gridview 中。
页面显示当前用户名,当该人上传文件时,一切正常。虽然当该用户点击搜索按钮时,所有记录都会显示并且我收到错误:
错误:列名“测试”无效
protected void ButtonSearch_Click(object sender, EventArgs e)
{
GridView1.Visible = true;
try
{
string UN = Session["New"].ToString();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlDataReader reader;
SqlCommand command = new SqlCommand();
command.CommandText = "SELECT * FROM UserUpload WHERE UserName = @un";
command.Parameters.Add(new SqlParameter("@un", UN));
command.Connection = conn;
conn.Open();
reader = command.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
conn.Close();
}
catch (Exception ex)
{
LabelMessage.Text = ("Error:" + ex.Message);
}
}
【问题讨论】: