Simple numbering in a database

Hi,

I have a treeview that load and saves the treeview-nodes to a database.
The table contains columns called NodeID and a ParentNodeID and other columns.

In de code-section I have wrote code to insert a folder-node into the treeview
My question is about the code-line that I have marked with an arrow.

With this code the programm inserts a complex string of letters and nummbers.
But I just want a simple numbering.

What can I do?

Greetings,

Peter Kiers






private void InsertNewFolder(TreeNode node)
        {
            DataRow row = null;
            DataRow ParentRow = null;
            DataTable dt = null;
            string NewText1 = "";
            try
            {
                if (InputBox.Show("New Folder", "Folder", ref NewText1, validation) == DialogResult.OK)
                {
                    ParentRow = (DataRow)node.Tag;
                    if (ParentRow == null) { return; }
                    dt = ParentRow.Table;
                    row = dt.NewRow();
                    row["NodeID"] = Guid.NewGuid().ToString(); <=====================================
                    row["ParentNodeID"] = ParentRow[dt.PrimaryKey[0].ColumnName].ToString();
                    row["Name"] = NewText1;
                    row["ImageIndex"] = 1;
                    row["ServSize"] = txtServSize.Text;
                    row["Cal"] = txtCal.Text;
                    row["Chol"] = txtChol.Text;
                    row["Fat"] = txtFat.Text;
                    row["Fib"] = txtFib.Text;
                    row["Carbs"] = txtCarbs.Text;
                    row["Sod"] = txtSod.Text;
                    row["Prot"] = txtProt.Text;
                    dt.Rows.Add(row);
                    TreeNode newNode = TreeViewUtil.GetTreeNodeFromDataRow(row, "Name");
                    node.Nodes.Add(newNode);
                    treeView1.SelectedNode = newNode;
                }
            }
            catch (Exception) { throw; }
        }

Open in new window

LVL 1
Peter KiersOperatorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Luis PérezSoftware Architect in .NetCommented:
You can use System.DateTime.Now.Ticks()

Hope that helps.
0
Peter KiersOperatorAuthor Commented:
No just simple numbering.
0
Luis PérezSoftware Architect in .NetCommented:
And what exactly do you want to say with "simple"?
0
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Peter KiersOperatorAuthor Commented:
f.e: in NodeId: 0

 in ParentNode Id: 1
0
johannodCommented:
Hi,

You can use the database's autonumber column type and retrieve the generated number when you need it. Full info here: http://msdn.microsoft.com/en-us/library/ks9f57t0%28v=vs.80%29.aspx

/Johan
0
Pratima PharandeCommented:
row["NodeID"] = (Convert.ToInt32( ParentRow[dt.PrimaryKey[0].ColumnName]) -1).ToString();
0
Luis PérezSoftware Architect in .NetCommented:
But how do you want to ensure the uniqueness of each node? The Guid.NewGuid.ToString() ensures that each new node in database has a unique ID. You need to ensure of this enforcement in your code logic.
0
AndyAinscowFreelance programmer / ConsultantCommented:
As far as I see it this will only add one record.  
Do you want each new record to have the ID of 0 ?  (which sounds like nonsense).

Do you require the following in the database (or something like it)?

parent ID 1    child ID 0
parent ID 1    child ID 1
parent ID 1    child ID 2
parent ID 2    child ID 0
parent ID 2    child ID 1
parent ID 3    child ID 0

....

0
Peter KiersOperatorAuthor Commented:
Yes, sorry for not being clear about my problem
But the last post of AndyAinscow is exactly what I wanted.


Peter
0
AndyAinscowFreelance programmer / ConsultantCommented:
OK.
This isn't quite so simple as you think.

Would any of these child records be moved to another parent?
Would any of these child records be deleted?

Put another way is this acceptable?

parent ID 1    child ID 0
parent ID 1    child ID 1
parent ID 1    child ID 3    ///NOTE parent ID 1    child ID 2 does not exist
parent ID 2    child ID 0
parent ID 2    child ID 1
parent ID 3    child ID 0
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Peter KiersOperatorAuthor Commented:
I give up.

Peter
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.