Solved

Help with one line of code

Posted on 2011-03-14
19
332 Views
Last Modified: 2013-12-17
Hello,

I have this methode below. The line marked with an arrow does not work.
The data that will be entered into the textbox will not be saved to the column
Data of the database.

But when i change the code to this it works:
row["Data"] = "TEST";

What should there be changed to get the content of the textbox into the column Data
of the database.

Peter
       
private void InsertNewItem(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"] = 3;
                row["SelectedImageIndex"] = 3;
                row["SortOrder"] = newindex;
                row["Data"] = textBox1.text <=========================
                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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 5
  • 2
  • +2
19 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 35126833
textBox1.Text

Capital letter
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 150 total points
ID: 35126835
Well, # is case-sensitive, so unless that is a type in the post it should say:
row["Data"] = textBox1.Text;

Open in new window

0
 
LVL 11

Expert Comment

by:JoeNuvo
ID: 35126842
How about this code?

row["Data"] = textBox1.Text.ToString();
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 1

Author Comment

by:peterkiers
ID: 35126865
row["Data"] = textBox1.Text.ToString();

is not working

Peter
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35126884
"not working" how? If a hard-coded string works then pulling the text from a textbox should also work. Assuming "textbox1" is a valid object and that there is actually some text in it.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 35126900
Any error message?

(The ToString shouldn't be required, Text ought to be suitable)
0
 
LVL 1

Author Comment

by:peterkiers
ID: 35126923
Carl_Tawn you right but still the code does not work!

I have this to save the textbox.text to the column Data of the database.

                row["Data"] = mmoNotes.Text.ToString();

And this for reading the data of the column Data and put it in the textbox

        private void tvNotes_AfterSelect(object sender, TreeViewEventArgs e)
        {
            DataRow row = e.Node.Tag as DataRow;
            mmoNotes.Text = row["Data"].ToString();
        }

The last methode works but not the first line.

P.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 35126938
String s = mmoNotes.Text.ToString();
row["Data"] = mmoNotes.Text.ToString(); //Breakpoint here - what is the value of s ?
0
 
LVL 1

Author Comment

by:peterkiers
ID: 35126943
No errors.

I think it called a logical error, no errors but it doesn't work either.


Peter
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 35126944
By the way how do you test?  I don't see any code for saving this to a database.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 35126991
I have attached the whole code.

Peter
MyApp.txt
0
 
LVL 1

Author Comment

by:peterkiers
ID: 35127019
This is the procedure that saves the treeview to the database:

        private void tbAccChan_Click(object sender, EventArgs e)
        {
            DataRow row = null;
            Hourglass(true);
            try
            {
                if (tvNotes.Nodes.Count == 0) { return; }
                row = (DataRow)tvNotes.Nodes[0].Tag;
                CommitHierarchy(DBConStr, row.Table.DataSet);
            }
            catch (Exception err) { MessageBox.Show(err.Message); }
            finally { Hourglass(false); }
        }

Peter
0
 
LVL 1

Author Comment

by:peterkiers
ID: 35127034
I quess I was looking at the wrong methode.

Because the methode above is the methode that saves the treeview to the database.
now I have to save the text of the textbox as well. How can I do that?

Peter
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 350 total points
ID: 35127055
Does this work?

private void tbAccChan_Click(object sender, EventArgs e)
        {
            DataRow row = null;
            Hourglass(true);
            try
            {
                if (tvNotes.Nodes.Count == 0) { return; }
                row = (DataRow)tvNotes.Nodes[0].Tag;
row["Data"] = textBox1.Text;
                CommitHierarchy(DBConStr, row.Table.DataSet);
            }
            catch (Exception err) { MessageBox.Show(err.Message); }
            finally { Hourglass(false); }
        }

0
 
LVL 1

Author Comment

by:peterkiers
ID: 35127075
When changes are made to the treeview and the user presses a button
that will save the changes to the database. These 3 methodes actually does this.

the "tbAccChan_Click" calls for the "CommitHierarchy" and this finally calls for the
"CommitToDataBase"methode.

So 1 one of these methodes has something to be changed.

Peter
3methodes.txt
0
 
LVL 1

Author Comment

by:peterkiers
ID: 35127090
it works but it doesn't take the right row.

Peter
0
 
LVL 11

Expert Comment

by:Kusala Wijayasena
ID: 35127156

Hi Peter,

row = (DataRow)tvNotes.Nodes[0].Tag

Open in new window


I have a doubt that above code is always referring Node[0]. Is it right ?

-Kusala  
0
 
LVL 1

Author Comment

by:peterkiers
ID: 35127169
yes this is right.
0
 
LVL 1

Author Comment

by:peterkiers
ID: 35127255
I give up.

Peter
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

630 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