M
mdb
I have an interest in minimizing the amount of data transfer between my
SQL server and my client in a networked environement. I have a table
with a large amount of data that has foreign key values pointing into
other tables that I need data from. The data from these child tables
are mostly string values that would be repeated many many times in the
resulting dataset if I just do a join and pull the value directly.
Here's an example:
MainTable:
keyId fkA fkB fkC fkD
0 0 1 1 0
1 0 0 2 1
2 4 2 9 3
....
....
2101 3 2 1 3
And my foreign key tables might look like:
TableA:
keyA Value
0 'This is the value for key 0'
1 'This is the value for key 1'
2 'This is the value for key 2'
3 'This is the value for key 3'
4 'This is the value for key 4'
.... and so on for the other foreign key tables (B, C, and D.)
In my client, I would like to end up with a result that shows the keyId,
and the Values for each of the foreign keys. I could easily do this
with a join, but then the values get transferred over and over for each
row, and that seems like an incredible waste of bandwidth. So instead,
I want to just transfer the data once, like so:
CREATE PROCEDURE GetValues
SELECT keyId,fkA,fkB,fkC,fkD FROM MainTable
SELECT * FROM TableA WHERE keyA IN (SELECT DISTINCT fkA FROM MainTable)
SELECT * FROM TableB WHERE keyB IN (SELECT DISTINCT fkB FROM MainTable)
SELECT * FROM TableC WHERE keyC IN (SELECT DISTINCT fkC FROM MainTable)
SELECT * FROM TableD WHERE keyD IN (SELECT DISTINCT fkD FROM MainTable)
and I execute this stored procedure as the source for a DataSet. This
results in the 'Tables' collection for my dataset having 5 entries. I
then create a relation on these tables programmatically:
DataSet ds = new DataSet();
ds.DataSource = (...the result of the EXEC GetValues...)
DataColumn parent, child;
child = ds.Tables[1].Columns["keyA"];
parent = ds.Tables[0].Columns["fkA"];
ds.Relations.Add(parent, child);
child = ds.Tables[1].Columns["keyB"];
parent = ds.Tables[0].Columns["fkB"];
ds.Relations.Add(parent, child);
child = ds.Tables[1].Columns["keyC"];
parent = ds.Tables[0].Columns["fkC"];
ds.Relations.Add(parent, child);
child = ds.Tables[1].Columns["keyD"];
parent = ds.Tables[0].Columns["fkD"];
ds.Relations.Add(parent, child);
So now, in my opinion, the datagrid should know how to display the
keyId, and each of the values, assuming I can configure it correctly.
This is the main question of this post - is this possible??
I've tried creating a TableStyle with appropriate DataGridColumnStyles
setting the 'MappingName' parameters to the DataColumn.ColumnName's of
the columns I wanted to display, but that didn't work too well. For
example,
DataGridTableStyle ts = new DataGridTableStyle();
DataGridColumnStyle cs;
cs = new DataGridTextBoxColumn();
cs.MappingName = ds.Tables[0].Columns["keyId"].ColumnName;
ts.GridColumnStyles.Add(cs);
cs = new DataGridTextBoxColumn();
cs.MappingName = ds.Tables[1].Columns["Value"].ColumnName;
ts.GridColumnStyles.Add(cs);
cs.MappingName = ds.Tables[2].Columns["Value"].ColumnName;
ts.GridColumnStyles.Add(cs);
ts.MappingName = ds.Tables[0].TableName;
dataGrid1.TableStyles.Clear();
dataGrid1.TableStyles.Add(ts);
dataGrid1.DataSource = ds;
Does all this make sense??? Is there a way to do what a I want to do,
or am I going to have to build up a ListView with the items I want?
SQL server and my client in a networked environement. I have a table
with a large amount of data that has foreign key values pointing into
other tables that I need data from. The data from these child tables
are mostly string values that would be repeated many many times in the
resulting dataset if I just do a join and pull the value directly.
Here's an example:
MainTable:
keyId fkA fkB fkC fkD
0 0 1 1 0
1 0 0 2 1
2 4 2 9 3
....
....
2101 3 2 1 3
And my foreign key tables might look like:
TableA:
keyA Value
0 'This is the value for key 0'
1 'This is the value for key 1'
2 'This is the value for key 2'
3 'This is the value for key 3'
4 'This is the value for key 4'
.... and so on for the other foreign key tables (B, C, and D.)
In my client, I would like to end up with a result that shows the keyId,
and the Values for each of the foreign keys. I could easily do this
with a join, but then the values get transferred over and over for each
row, and that seems like an incredible waste of bandwidth. So instead,
I want to just transfer the data once, like so:
CREATE PROCEDURE GetValues
SELECT keyId,fkA,fkB,fkC,fkD FROM MainTable
SELECT * FROM TableA WHERE keyA IN (SELECT DISTINCT fkA FROM MainTable)
SELECT * FROM TableB WHERE keyB IN (SELECT DISTINCT fkB FROM MainTable)
SELECT * FROM TableC WHERE keyC IN (SELECT DISTINCT fkC FROM MainTable)
SELECT * FROM TableD WHERE keyD IN (SELECT DISTINCT fkD FROM MainTable)
and I execute this stored procedure as the source for a DataSet. This
results in the 'Tables' collection for my dataset having 5 entries. I
then create a relation on these tables programmatically:
DataSet ds = new DataSet();
ds.DataSource = (...the result of the EXEC GetValues...)
DataColumn parent, child;
child = ds.Tables[1].Columns["keyA"];
parent = ds.Tables[0].Columns["fkA"];
ds.Relations.Add(parent, child);
child = ds.Tables[1].Columns["keyB"];
parent = ds.Tables[0].Columns["fkB"];
ds.Relations.Add(parent, child);
child = ds.Tables[1].Columns["keyC"];
parent = ds.Tables[0].Columns["fkC"];
ds.Relations.Add(parent, child);
child = ds.Tables[1].Columns["keyD"];
parent = ds.Tables[0].Columns["fkD"];
ds.Relations.Add(parent, child);
So now, in my opinion, the datagrid should know how to display the
keyId, and each of the values, assuming I can configure it correctly.
This is the main question of this post - is this possible??
I've tried creating a TableStyle with appropriate DataGridColumnStyles
setting the 'MappingName' parameters to the DataColumn.ColumnName's of
the columns I wanted to display, but that didn't work too well. For
example,
DataGridTableStyle ts = new DataGridTableStyle();
DataGridColumnStyle cs;
cs = new DataGridTextBoxColumn();
cs.MappingName = ds.Tables[0].Columns["keyId"].ColumnName;
ts.GridColumnStyles.Add(cs);
cs = new DataGridTextBoxColumn();
cs.MappingName = ds.Tables[1].Columns["Value"].ColumnName;
ts.GridColumnStyles.Add(cs);
cs.MappingName = ds.Tables[2].Columns["Value"].ColumnName;
ts.GridColumnStyles.Add(cs);
ts.MappingName = ds.Tables[0].TableName;
dataGrid1.TableStyles.Clear();
dataGrid1.TableStyles.Add(ts);
dataGrid1.DataSource = ds;
Does all this make sense??? Is there a way to do what a I want to do,
or am I going to have to build up a ListView with the items I want?