[ASP.NET C#]在gridview中使用过滤器仅显示一条记录

时间:2016-06-06 16:03:09

标签: c# asp.net gridview

嗨,我有一个问题,就像学期和学校一样搜索2个值,它只给我一条记录,而我找到了至少30条记录。

string conn = ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString;
        using (SqlConnection sqlcon = new SqlConnection(conn))
        {
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = "SELECT *FROM tblEvaluation WHERE Semester LIKE '%' + @sem +  '%' and SchoolYear like '%' + @sy +  '%'";
                cmd.Connection = sqlcon;
                cmd.Parameters.AddWithValue("@sem", DropDownList1.Text);
                cmd.Parameters.AddWithValue("@sy", DropDownList2.Text);
                DataTable dt = new DataTable();
                using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                {
                    sda.Fill(dt);
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                }
            }
        }

0 个答案:

没有答案