DataGridView的问题C# 多存在一定关系的个表的显示

来源:百度知道 编辑:UC知道 时间:2024/05/27 04:02:29
现在有两个表typhoonlist和tPathInfo,它们之间靠tID联系
Typhoonlist的内容是有哪些typhoon
tPathInfo的内容是每一个typhoon的详细信息
现在需要在单击dataGridView1的某一条typhoon时候,触发dataGridView1_CellContentClick事件,开始调用tInfoDisplay(),tInfoDisplay()需要实现的功能就是在dataGridView2中显示出当前dataGridView1中这一条typhoon的详细信息(也就是显示tPathInfo的部分内容)。敬请高手帮助我完成tInfoDisplay()的编写
鉴于之前没有可行答案,给出的奖励分数不得不还给系统,这次决定完成后给再更多的分。谢谢~~~~
private void tInfoDisplay()
{
SqlConnection thisConnection = new SqlConnection(
@"Server=(local);Integrated Security=True;" +
"Database=Typhone");

SqlDataAdapter thisAdapter = new SqlDataAdapter(
"SELECT tID, tName FROM typhoonlist", thisConnection);

SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);

DataSet thisDataSet = new DataSet();// Create DataSet to contain related data tables, rows, and columns

1,public SqlConnection scn;
public string connectionstring = "server=本机;database=数据库名;uid=sa;pwd=数据库密码";
public SqlDataAdapter sda;
public SqlCommand cmd;
public DataSet ds;

1,建一个TEXTBOX控件,比如名叫textRoomID

2,DataGridview控件中,默认单击一个单元格通常是选中单元格,而不是选中单元格所在整行:
在MouseClick事件里写:dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Selected = true;
this.textRoomID.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
scn = new SqlConnection(connectionstring);
try
{
scn.Open();
}
catch (Exception ec)
{
MessageBox.Show("连接数据库失败!");
}
sda = new SqlDataAdapter();
ds = new DataSet();
cmd = scn.CreateCommand();
string query = "select