|
why dont you go throught the table sequencially and put the value where you need it in the tree?
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
Do you already use recursion. You would start with rows having parent equal to null and then search the data recursively (while building the tree).
Perhaps if you could explain a bit more about the problem it would be easier to make suggestions.
|
|
|
|
|
Yes I do use recursion. I'll try to explain it more in depth. I am building a graph using a 3rd party DLL (see: yWorks.com). The model builds around 4k relationships every 10 seconds when viewing a large amount of data (95k relationships). The model is built on levels, e.g: when the user first opens the program, it retrieves all the data for the whole model, and builds 2 levels. The user can then expand to as many levels as they like.
Below is a quick sample of the code I use to build the model.
private void BuildModel(Node node, int currentLevel)
{
if ((currentLevel + 1) > _modelLevel)
return;
currentLevel++;
DataRow[] matchingRows = _relationshipDataSet.Tables[0].Select("[" + PARENT + "] = '" + node.Name + "'");
if (matchingRows == null || matchingRows.Length == 0)
return;
foreach (DataRow row in matchingRows)
{
string childName = row[CHILD].ToString();
string nodeHashCode = childName + node.Name + node.GetHashCode().ToString();
if (!_graphNodeHashSet.Contains(nodeHashCode))
{
_graphNodeHashSet.Add(nodeHashCode);
BuildModel(childNode, currentLevel);
}
else
{
List<node> nodeList = new List<node>();
bool isValid = _nodeDictionary.TryGetValue(childName, out nodeList);
if (isValid)
{
foreach (Node childNode in nodeList)
{
BuildModel(childNode, currentLevel);
}
}
}
}
}</node></node>
Hope this helps some more. I am also using .NET 2.
Regards,
Gareth.
(FKA gareth111)
modified on Friday, February 6, 2009 4:48 AM
|
|
|
|
|
Gareth H wrote: retrieves a tree structure
Are you building a TreeView?
If so, I would likely do it as:
0) Query the root-level data (parents)
1) Iterate those values
1.0) Insert the value to the TreeView
1.1) Query for the children of that value
1.2) Iterate the children
1.2.0) Add the child to the parent's node
... and so on
(You do have an index for the parents, yes?)
Or, perhaps, this way (which uses more resources):
0) Query all the data, as you do now
1) Iterate the parents
1.0) Insert the value to the TreeView
1.1) Also add the parent's ID and node to a Dictionary<id,node>
2) Iterate the children
2.0) Get the Parent's node from the Dictionary
2.1) Add the child to the parent's node
2.2) If the children have children, add the node to a Dictionary (the same one or another, depending on your schema)
... and so on
|
|
|
|
|
Why are you storing this data in a DataSet? The overhead in maintaining this is very heavy, and won't help your situation. If you are using Sql Server 2005/2008, you could always use Common Table Expressions to get the hierarchical data out of the database in a hierarchical fashion far faster than you could using the dataset.
|
|
|
|
|
The project is database in-dependent, ie: we support SQL Server 2005/2008, Oracle, Access, etc so using something that would work on SQL Server but not Oracle wouldn't really suit my situation.
The data is currently retrieved from the DB in chunks (around 5k rows), stored in a data set. The reason I am storing in a data set is because that is the format which it is given to me in (my code does not handle data retrieval). However, if you know of a better way that isn't database specific, I could look into this/talk to my supervisor.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
For really fast tree retrieval use a trigger that uses CTEs to keep a text lineage column update, so you have a list of parents: /1/2/3/4/.
This makes selection quite fast, for example to grab an entire subtree you can just do a where lineage like %/num/%, etc.
|
|
|
|
|
Hello.hi have a problem whit a programe where i whant to send data from textbox to datagridview in a diferent form.
|
|
|
|
|
create a public method in the form with the datagrid that takes a string paramter.
then from the textbox form call the method and pass the textbox.Text value
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
And now the difficult part, pseudo code to C#...
|
|
|
|
|
its prob not what he is trying to ask anyway
OP, give use some more info
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
can somebody help me how to connect a database server located in unix box..
i want connection string..
Thank in advance
vikas da
|
|
|
|
|
I know nothing about connection strings (I'm not from Barcelona though), but these people do[^].
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, June 10, 2011 11:32 AM
|
|
|
|
|
Doesn't depend on the os, it depends on the database. It is a sql server, sybase, mysql, postgre etc.?
sql server doesn't run on unix
|
|
|
|
|
Thanks for reply..
its mysql... do i need to do anything extra to connect unix box...for database access
vikas da
|
|
|
|
|
No, all you have to do is follow the link Luc Pattyn posted, so that you get the correct connection string. (Don't know if you need a client library for mysql at the client).
|
|
|
|
|
thanks to Luc Pattyn and SeMartens have a nice time ... i am trying it all
vikas da
|
|
|
|
|
Hi there,
When building a WinForms project, im getting this error :
Unable to create a manifest resource name for "Forms\MainForm.resx". Could not find file xxxxxxx
I checked and i saw that the file MainForm.resx is not missing. Can anyone tell me what's the problem here?
Thank you.
|
|
|
|
|
What file is file 'xxxxxxxx'?
|
|
|
|
|
that is the one missing, according to the error message.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, June 10, 2011 11:32 AM
|
|
|
|
|
*grumble* whats the file *grumble*
coffee anyone?
|
|
|
|
|
I can't tell what it is about, it is missing after all, and the name isn't telling us anything, is it?
BTW: too much coffee isn't good for your nerves.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, June 10, 2011 11:33 AM
|
|
|
|
|
Maybe it is a bit, maybe his source files where moved around, it is looking in a folder called Forms isn't it..?
|
|
|
|
|
How to create a wap browser,It can visit the wap web site.
which one has the source code?
|
|
|
|
|
Member 4709907 wrote:
How to create a wap browser,It can visit the wap web site.
which one has the source code?
[sarcasm] Do you want to create it yourself, or do want me to send the codez? [/sarcasm]
|
|
|
|