我已经取三个DataGridView列名为"ID","第一","最后的"
数据库。
现在我想,当我点击第一的DataGridView行,然后显示相关信息,根据"身份证"。
同样,当我点击第二的DataGridView行的相关信息显示根据"身份证"......
同样,当我点击第三排的DataGridView相关信息显示。
我米使用此代码,但一些小error.so它不告诉properly.So
正确的方法和代码。
该代码是----
|舒克拉爬完:OriginalGriffprivate void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
string connectionString = ConfigurationSettings.AppSettings["cnn"];
//int row = e.RowIndex + 1;
string selectSQL = "SELECT Prefix,first,last FROM contactmngt where id= " + dataGridView1 + "";
SqlCommand cmd = new SqlCommand(selectSQL, cnn);
SqlDataReader dr;
cnn.Open();
dr = cmd.ExecuteReader();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.SelectCommand = cmd;
if (dr.Read())
{
label11.Text = dr[0].ToString();
label12.Text= dr[1].ToString();
label13.Text = dr[2].ToString();
}
cnn.Close();
}
catch (Exception)
{
//Response.Write(ex.ToString());
}
}