我正在尝试将相同的数据读取器对象绑定到 2 个控件。一个是 gridview,第二个是 formview。gridview 正在绑定,但 formview 没有。即使我在绑定两者后关闭对象。谁能告诉我这是否可能。如果是,那怎么办?
这是我的代码:-
SqlConnection con = new SqlConnection(getconnectionstring());
SqlCommand cmd = new SqlCommand();
SqlCommand cmd1 = new SqlCommand();
//cmd.CommandText = "SELECT firstname,lastname FROM crudtable";
cmd.CommandText = "SELECT firstname,lastname FROM crudtable";
cmd1.CommandText = "SELECT firstname FROM crudtable";
cmd.Connection = con;
cmd1.Connection = con;
con.Open();
SqlDataReader reader ;
SqlDataReader reader1;
reader = cmd.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
FormView1.DataSource = reader;
FormView1.DataBind();
reader.Close();
reader1 = cmd1.ExecuteReader();
ddl.DataSource = reader1;
ddl.DataTextField = "firstname";
ddl.DataBind();
提前致谢。