3 Replies - 25544 Views - Last Post: 22 December 2008 - 10:59 AM Rate Topic: -----

#1 Goose1  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 15-December 08

Creating a Save Button

Post icon  Posted 21 December 2008 - 02:51 PM


I'm just playing around with Visual C# for the first time and I've created all the bits I need except I need the user of the application to be able to save the information they enter into the Listbox.

I don't want the code to just be given to me (kind of avoids the point of trying to pick this up!) I just need to know if firstly I can do it and just a point in the right direction.

I don't need anything complicated just a way of being able to save the information inputted. As I'm new to this I apologise if there's anything I've omitted from this but any help would be greatly appreciated.

Many Thanks

Is This A Good Question/Topic? 1
  • +

Replies To: Creating a Save Button

#2 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 782
  • View blog
  • Posts: 5,101
  • Joined: 08-December 08

Re: Creating a Save Button

Posted 21 December 2008 - 03:18 PM

You have to create a new instance of StreamWriter, to write the data to a file.
StreamWriter stream = new StreamWriter ("FILE_PATH");

Then, you have to parse through all the items in the list and get their value (string), writing them line-by-line in the specified file. That's pretty much it.

This post has been edited by Core: 21 December 2008 - 03:28 PM

Was This Post Helpful? 0
  • +
  • -

#3 beatles1692  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 62
  • Joined: 03-December 08

Re: Creating a Save Button

Posted 22 December 2008 - 06:31 AM

You can save your info in a file or a database.
If you want to save it in a file , you can use a Stream to write info.To work with files you can use System.IO.File class that has some static methods to work with files.After writing info to stream you should flush it so the changes you have made be written to hard disk and you should close the stream so that another processes can access the file.
(When you are working with disposable objects , its a good practice to use using keyword around your variables , so that they will be disposed after being used)
for example
using(var fileStream=File.CreateText(myPath))
//do what you want to do

If you want to use a database you should decide what RDBMS(relational database management system) you want to use (MS Access,SQL Server,MySql and etc).You should create a database and a table for your info.Then you can connect to your database using ADO.net and insert info into your table.

This post has been edited by beatles1692: 22 December 2008 - 06:33 AM

Was This Post Helpful? 0
  • +
  • -

#4 tody4me  Icon User is offline

  • Banned
  • member icon

Reputation: 12
  • View blog
  • Posts: 1,398
  • Joined: 12-April 06

Re: Creating a Save Button

Posted 22 December 2008 - 10:59 AM

Excuse you, M$ Access is NOT a RDBMS! It's a fake wanna be storage application, but not relational at all. You can create tables, FK's and PK's and sometimes they work, but it's not the intent.

This post has been edited by tody4me: 22 December 2008 - 11:00 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1