private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=数据库;Integrated Security=True"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{ cmd.CommandText = @"select * from T_GongsiXinxi";
//conn.Open();
DataSet DS = new DataSet();
SqlDataAdapter DA = new SqlDataAdapter(cmd);
DA.Fill(DS);
this.dataGridView1.DataSource = DS.Tables[0];
conn.Close();
}
表中有数据吗?
怀懝是个空表.
this.dataGridView1.DataBind();
conn.Close();
确实是这个事件问题,先用一个Button测试下吧
------------------------------------------------
//是CellContentClick 事件的问题
//你这个代码根本没执行 知道吗?
//CellContentClick 事件,必须单元格里有内容(文字) 点击了才出发
//不知道你为什么要用这个事件? 换个Button先试一下吧
这里设置一个断点,看看能进去不,还有DS有值没有
using (SqlConnection conn = new SqlConnection(@""))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand("select * from T_GongsiXinxi",conn))
{
DataSet DS = new DataSet();
SqlDataAdapter DA = new SqlDataAdapter(cmd);
DA.Fill(DS);
this.dataGridView1.DataSource = DS.Tables[0];
conn.Close();
}
}