ASP.net 按条件查询数据库的问题
protectedvoidButton2_Click(objectsender,EventArgse){stringname=Button2.Text.ToString(...
protected void Button2_Click(object sender, EventArgs e)
{
string name = Button2.Text.ToString();
DataSet ds = GetDataSet2(name);
GridView1.DataSource = ds;
GridView1.DataBind();
}
DataSet GetDataSet2(string name)
{
SqlConnection myCon = new SqlConnection();
myCon.ConnectionString = "Data Source=wqy-PC;Initial Catalog=学生注册系统;Integrated Security=True";
myCon.Open();
SqlCommand selectCMD = new SqlCommand("SELECT 申请学号,姓名,院系 FROM 缓缴费表 where 院系="+Label6.Text.Trim() , myCon);
//这一句中院系在SQL中是varchar(10)类型的,Label6.Text=计算机,查询出来本该显示学院为计算机的字段,但执行结果出错为找不到计算机列名,但如果按一个int型的来查询就是对的,这是为什么呢?
SqlDataAdapter custDA = new SqlDataAdapter();
custDA.SelectCommand = selectCMD;
DataSet custDS = new DataSet();
custDA.Fill(custDS, "缓缴费表");
myCon.Close();
return custDS;
} 展开
{
string name = Button2.Text.ToString();
DataSet ds = GetDataSet2(name);
GridView1.DataSource = ds;
GridView1.DataBind();
}
DataSet GetDataSet2(string name)
{
SqlConnection myCon = new SqlConnection();
myCon.ConnectionString = "Data Source=wqy-PC;Initial Catalog=学生注册系统;Integrated Security=True";
myCon.Open();
SqlCommand selectCMD = new SqlCommand("SELECT 申请学号,姓名,院系 FROM 缓缴费表 where 院系="+Label6.Text.Trim() , myCon);
//这一句中院系在SQL中是varchar(10)类型的,Label6.Text=计算机,查询出来本该显示学院为计算机的字段,但执行结果出错为找不到计算机列名,但如果按一个int型的来查询就是对的,这是为什么呢?
SqlDataAdapter custDA = new SqlDataAdapter();
custDA.SelectCommand = selectCMD;
DataSet custDS = new DataSet();
custDA.Fill(custDS, "缓缴费表");
myCon.Close();
return custDS;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询