M
Mikael Syska
Hi,
I have 2 talbes in a DataSet, and made a DataRelation between the 2
tables in the DataSet.
One of the Tables are displayed in a datagrid, and when one of them is
selected in the datagrid I want its childcolumns to be displayed in a
second datagrid.
How can I filter the dataset or get only the related data into the
second datagrid?
I totally blank on this one.
I use ByteFX to connect to a mysql database.
Here are my code:
private void Form1_Load(object sender, System.EventArgs e)
{
MySqlConnection thisConnection = new MySqlConnection("Server=syska.dk;
Username=root; Password=supermand; Database=c-sharp;");
MySqlDataAdapter thisPollAdapter = new MySqlDataAdapter("SELECT * FROM
poll", thisConnection);
MySqlDataAdapter thisOptionAdapter = new MySqlDataAdapter("SELECT *
FROM pollOption", thisConnection);
thisPollAdapter.Fill(thisDataSet, "first");
thisOptionAdapter.Fill(thisDataSet, "second");
dataGrid.DataSource = thisDataSet.Tables["first"];
DataRelation thisRelation = new DataRelation("thisRelation",
thisDataSet.Tables[0].Columns["pollId"],
thisDataSet.Tables[1].Columns["pollId"]);
// MessageBox.Show( thisDataSet.Tables[1].ParentRelations. );
// her skal de columns smides ind som passer til det ID som er valgt i
det anden datagrid
// dataGrid1.DataSource =
}
As you can see, I havent made anything fancy yet, are this the right way
to go, or are there are better way of doing this, I dont want to get all
the data every time, I choose a new row in the first datagrid..
kind regards
Mikael Syska
I have 2 talbes in a DataSet, and made a DataRelation between the 2
tables in the DataSet.
One of the Tables are displayed in a datagrid, and when one of them is
selected in the datagrid I want its childcolumns to be displayed in a
second datagrid.
How can I filter the dataset or get only the related data into the
second datagrid?
I totally blank on this one.
I use ByteFX to connect to a mysql database.
Here are my code:
private void Form1_Load(object sender, System.EventArgs e)
{
MySqlConnection thisConnection = new MySqlConnection("Server=syska.dk;
Username=root; Password=supermand; Database=c-sharp;");
MySqlDataAdapter thisPollAdapter = new MySqlDataAdapter("SELECT * FROM
poll", thisConnection);
MySqlDataAdapter thisOptionAdapter = new MySqlDataAdapter("SELECT *
FROM pollOption", thisConnection);
thisPollAdapter.Fill(thisDataSet, "first");
thisOptionAdapter.Fill(thisDataSet, "second");
dataGrid.DataSource = thisDataSet.Tables["first"];
DataRelation thisRelation = new DataRelation("thisRelation",
thisDataSet.Tables[0].Columns["pollId"],
thisDataSet.Tables[1].Columns["pollId"]);
// MessageBox.Show( thisDataSet.Tables[1].ParentRelations. );
// her skal de columns smides ind som passer til det ID som er valgt i
det anden datagrid
// dataGrid1.DataSource =
}
As you can see, I havent made anything fancy yet, are this the right way
to go, or are there are better way of doing this, I dont want to get all
the data every time, I choose a new row in the first datagrid..
kind regards
Mikael Syska