Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do you save or change data typed into a textbox using VB.NET? 2

Status
Not open for further replies.
Mar 27, 2003
9
US
Hi all,

Ive been looking for the solution with no avail. I'm new to programming but catch on quick. I'll be as detailed and basic as I can.

I have created a form, which has one textbox with the text property left empty, and one button labled Save.

When I run the application, I want to be able to type data into the textbox, click SAVE and then close the application. When the application is reopened the data I previously entered into the textbox is there.

I know it has to be a simple solution. I got this to work using a datagrid and a database but that is just too time consuming. Especially when I just want to change the textbox.text property and Save it.

Hope someone will help. Thanks much!!!
 
When SAVE is pressed, write the textbox text into a file. When the application comes up, it must read that file and display whatever is in it.

__________________________________________
Try forum1391 for lively discussions
 
Thanks Dimandja,

I first tried doing this but I couldnt get my code to work. Do you have some simple code in doing this without much trouble? I appreciate your response so quickly. I figured this was the easiest way.
 
Code:
  Sub SaveValue()
    Dim ds As New DataSet()
    Dim dt As New DataTable()
    Dim dr As DataRow
    dt.Columns.Add("TextValue")
    dr = dt.NewRow
    dr.Item("TextValue") = TextBox1.Text
    dt.Rows.Add(dr)
    ds.Tables.Add(dt)
    ds.WriteXml("TextValue.xml")
  End Sub

  Sub LoadValue()
    Dim ds As New DataSet()
    ds.ReadXml("TextValue.xml")
    TextBox1.Text = ds.Tables(0).Rows(0).Item("TextValue")
  End Sub

XML and Datasets are your friend!

-Rick

----------------------
 
Thanks ThatRickGuy,

1 problem - I am receiving an error;
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in system.xml.dll

happens at line - ds.ReadXml("TextValue.xml")
 
That's probably because the first time you run the program, that file does not yet exist.

Try Catch that read to go aroung the problem.

__________________________________________
Try forum1391 for lively discussions
 
Dimandja,

Exactly!!, I figured it out right after I sent the post. I just opened Microsoft Excel and saved a blank xml.

Now I have one other error.

An unhandled exception of type 'System.ArgumentException' occurred in system.data.dll

Additional information: Column 'TextValue' does not belong to table DocumentProperties.

on line - TextBox1.Text = ds.Tables(0).Rows(0).Item("TextValue")
 
The solution is the same. That file is empty, althoughj it exists. Try letting SaveValue() do its thing, the first time around: don't create an empty file at startup.

__________________________________________
Try forum1391 for lively discussions
 
Code:
 Sub LoadValue()
    if system.io.file.exists("TextValue.xml") then
      Dim ds As New DataSet()
      ds.ReadXml("TextValue.xml")
      TextBox1.Text = ds.Tables(0).Rows(0).Item("TextValue")
    end if
  End Sub

violla!

-Rick

----------------------
 
Hey Guys,

I got it to work!!Thanks a million!! Do you know of some good books I can purchase that would have this information in it? Like I said earlier I am new to programming but have been successful in creating quite a few, large Visual Basic programs.
Again, thanks for the info and the help!!! I may have other questions later but that got me past the first hurdle.

Sincerely, Brian
 
I'm not much of a book reader. More of a reference manual kinda guy. Google is my friend ;) and Intellisence is my keyword guide. In the past though I liked Dan Appleman<sp?>'s books. The Deitle and Wrox books weren't worth much. The both taught some basic syntax but didn't really touch on design which is the major difference from vb 6.

If you find any good books though, let me know.

-Rick

----------------------
 
I am more of a tactician guy. I'll give any strategy you need in order to tackle a programming problem.

As for references, like Rick, Google comes first -- short and to the point. I have bought many books, but after an average perusal time of 30 minutes, I usually put them on my shelf for ever -- rarely to be reopened again.

But remember, once you start coding, every line of code you write becomes your best reference.

__________________________________________
Try forum1391 for lively discussions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top