.net开发机票查询
我想实现的效果是,点击哪一行,(我用DataGridView做的),GroupBox航班详细信息中显示出对应的。下面是我写的代码private void dgvTicketInfo_MouseClick(object sender, MouseEventArgs e)
{
try
{
DBHelper.con.Open();
int Id = Convert.ToInt32(dgvTicketInfo.SelectedRows[0].Cells["Id"].Value);
string sql = string.Format("select LeaveCity,Destination,LeaveTime,SecondClass,FirstClass from TicketInfo where Id={0}", Id);
SqlCommand com = new SqlCommand(sql, DBHelper.con);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
txtTo.Text = reader[0].ToString();
txtFrom.Text = reader[1].ToString();
txtLeaveTime.Text = reader[2].ToString();
txtSecondClass.Text = reader[3].ToString();
txtFirstClass.Text = reader[4].ToString();
}
reader.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
DBHelper.con.Close();
}
航班详细信息是一个grp,里面又多个Text box 想选中DGV里面的某一列,显示在下面的Text box里(不可编辑)