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 5 2335
Mikael,
It's relatively easy. For the data source on the child grid, set it to
the DataRelation object that relates the two grids.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Mikael Syska" <ne**********@syska.dk> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... 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
Hey,
Fairly new to C#,
Can you give me a example
Can't seem to get the idea of how it knows witch item is selected in the
first datagrid, but you can probebly give me a breef description of it
kind regards
Mikael Syska
Nicholas Paldino [.NET/C# MVP] wrote: Mikael,
It's relatively easy. For the data source on the child grid, set it to the DataRelation object that relates the two grids.
Hope this helps.
Mikael,
You would want to do this:
// The grid is named childDataGrid, the DataSet is named dataSet.
childDataGrid.DataSource = dataSet.Relations[0];
You can substitute the relation for the proper one. The data set knows
it is a relation and will select the appropriate rows.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Mikael Syska" <ne**********@syska.dk> wrote in message
news:ui**************@TK2MSFTNGP12.phx.gbl... Hey,
Fairly new to C#,
Can you give me a example
Can't seem to get the idea of how it knows witch item is selected in the first datagrid, but you can probebly give me a breef description of it
kind regards Mikael Syska
Nicholas Paldino [.NET/C# MVP] wrote: Mikael,
It's relatively easy. For the data source on the child grid, set it to the DataRelation object that relates the two grids.
Hope this helps.
Nicholas,
I have just tried what you said...
now the code look like this:
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"]);
// My other datagrid1, this seems to work but no data is displayed
dataGrid1.DataSource = thisDataSet.Relations["thisRelation"];
// This gives me a error.... System.IndexOutOfRangeException: Cannot
find relation 0
// dataGrid1.DataSource = thisDataSet.Relations[0];
Can u see any errors or other mistyped things, cause it aint working....
Its so damm annoying that it aint working :-(
Nicholas Paldino [.NET/C# MVP] wrote: Mikael,
You would want to do this:
// The grid is named childDataGrid, the DataSet is named dataSet. childDataGrid.DataSource = dataSet.Relations[0];
You can substitute the relation for the proper one. The data set knows it is a relation and will select the appropriate rows.
Tried a little more, and came a little closer, added this line to the
code and the Relation comes in the first DataGrid, but I would prefer
the other option with 2 datagrids.....
thisDataSet.Relations.Add(thisRelation);
Hope u have a solution for me
thanks on advance
Mikael Syska
Mikael Syska wrote: Nicholas,
I have just tried what you said...
now the code look like this: 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"]);
// My other datagrid1, this seems to work but no data is displayed dataGrid1.DataSource = thisDataSet.Relations["thisRelation"];
// This gives me a error.... System.IndexOutOfRangeException: Cannot find relation 0 // dataGrid1.DataSource = thisDataSet.Relations[0];
Can u see any errors or other mistyped things, cause it aint working....
Its so damm annoying that it aint working :-(
Nicholas Paldino [.NET/C# MVP] wrote:
Mikael,
You would want to do this:
// The grid is named childDataGrid, the DataSet is named dataSet. childDataGrid.DataSource = dataSet.Relations[0];
You can substitute the relation for the proper one. The data set knows it is a relation and will select the appropriate rows.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stylus Studio |
last post by:
DataDirect XQuery(TM) is the First Embeddable Component for XQuery That
is Modeled after the XQuery API for Java(TM) (XQJ)
BEDFORD, Mass.--Sept. 20, 2005--DataDirect Technologies...
|
by: PawelR |
last post by:
Hello Group,
Sorry my english is very little.
I have problem with show data from Table from DataSet in textBox.
In my apps I have "typed DataSet" myDS with table TabPerson
On Form I have...
|
by: Brian Smith |
last post by:
I have a .aspx page (we'll call it Form1) with a
datagrid on it. The datagrid is populated from a dataset
that I manually entered data into (the data isn't in a
database). The datagrid on Form1...
|
by: jcfilth |
last post by:
Hello,
I have created an asp.net web page with 3 datagrids. Every datagrid
binds to a diferent sql query, against a sql server. I first bind
one, then the other and then the last, all using code...
|
by: Luis Esteban Valencia |
last post by:
I have this
i need to show the datagrid with columns of 2 datatables
Dim myadap As New SqlDataAdapter
myconn.Open()
myadap.TableMappings().Add("Table", "vistaUsuarios")
|
by: yuanh23 |
last post by:
Hi,
I have 3 talbes "customers","orders","details". i wanna to use 3 datagrids
to show those tables. and when the selected row in parent talbe changes, the
selected row in child table changes...
|
by: cooltech77 |
last post by:
Hi,
I am trying to build the following functionality in the datagrid.
I have a lot of columns in the datagrid which are being populated from the
database and the user needs to scroll...
|
by: DanThMan |
last post by:
Hi All,
Here's how my data looks. Two tables. The first has all the data in
"expanded" form, the second has just "ID" data in "pivoted" form.
Here's the "expanded" table:
DataID | RowID |...
|
by: simonyong |
last post by:
hello, everyone
Sorry for disturb..
im newbie to asp.net
im trying to do a task that as below:
In a SAME datagrid, it ll show all data when user key in key word in textbox...
datagrid will...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |