Solved

Save the text of a textbox to the database too

Posted on 2011-03-11
7
295 Views
Last Modified: 2013-12-17
Hi,

I have a treeview on the left and a textbox on the right devided with a splitter.
The treeview is saved to a database. Now I want the content of the textbox
saved to the database too.

I have this code in the code section.
What is the right way to save the content of the textbox
in to the database. I have tried to write the onle line
myself but it doesn't do what I want. I have marked the
line with an arrow. What should this be to save the content
of the textbox to a database?

Peter
private void InsertNewNode(TreeNode node)
        {
         DataRow row = null;
         DataRow ParentRow = null;
         DataTable dt = null;
         int newindex = 0;
         try
         {
             ParentRow = (DataRow)node.Tag; 
             if (ParentRow == null) { return; }
             newindex = int.Parse(ParentRow["SortOrder"].ToString()) + 1;
             dt = ParentRow.Table;
             row = dt.NewRow();
             row["ModelID"] = int.Parse(ParentRow["ModelID"].ToString());
			 row["NodeID"] = Guid.NewGuid().ToString();
			 row["ParentNodeID"] = ParentRow[dt.PrimaryKey[0].ColumnName].ToString();
             row["Description"] = "New Node";
			 row["ImageIndex"] = 1;
			 row["SelectedImageIndex"] = 2;
             row["SortOrder"] = newindex;
             row["Data"] = textBox1;   <===========================

             dt.Rows.Add(row);
             TreeNode newNode = GetTreeNodeFromDataRow(row, "Description");
             node.Nodes.Add(newNode);
             tvNotes.SelectedNode = newNode; 
         }
         catch (Exception) 
		 {
			 throw;
		 }

      }

Open in new window

0
Comment
Question by:peterkiers
  • 4
  • 3
7 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 35112032
row["Data"] = textBox1.Text;
I think that is what you want
0
 
LVL 1

Author Comment

by:peterkiers
ID: 35112148
Oke, and I know its another question but perhaps you know the answer to that too.

I have to use the treeview.afterselect event
When i click on a node the text in the textbox that is associated with that node
have to be displayed.

Do you have any idea how to?

P.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 35112232
I'm not certain what you mean.
Do you mean something like
textBox1.Text = node.Text;  //not certain if node has a Text property
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 1

Author Comment

by:peterkiers
ID: 35112257
I don't get further than this:

private void tvNotes_AfterSelect(object sender, TreeViewEventArgs e)
{
       textBox1.Text = ?????????
}

P.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 35112272
What I meant is:

When a node is selected in the treeview
then de text of column Data of the row
has to be displayed in the textbox

P.
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 35112287
TreeViewEventArgs has a node property - the node of the treeview being selected.  Have a look at what properties that exposes to find out what you need to be displayed.

textBox1.Text = e.Node.Text;  // Is this what you want?
0
 
LVL 1

Author Comment

by:peterkiers
ID: 35112460
Thank you for the help

Peter
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Reading the Web.Config using IIS 7.5? 4 38
SqlDataBase 7 48
SqlDependency to get update from sql to my c# app 2 41
FTP file download using c# 3 23
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question