我想用数据库中的数据填充 GridView,并让用户选择显示“Cursussen”表的哪一部分。他可以通过更改下拉框中的参数选择来做到这一点。
错误: 方法“Add”没有重载需要 2 个参数。
protected void Page_Load(object sender, EventArgs e)
{
ConnectionStringSettings planner =
ConfigurationManager.ConnectionStrings["CursusDatabase"];
DbConnection connection = new SqlConnection(planner.ConnectionString);
DbCommand cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText =
"SELECT * FROM Cursussen " +
"WHERE CursusId = @CursusId";
cmd.Parameters.Add("CursusId", DropDownList1.SelectedValue); // <-- here
connection.Open();
DbDataReader rdr = cmd.ExecuteReader();
DataTable planning = new DataTable();
planning.Load(rdr);
connection.Close();
GridView1.DataSource = planning;
GridView1.DataBind();
}
}