Record-based file storage

  • Thread starter Thread starter Tore Aursand
  • Start date Start date
T

Tore Aursand

Hi!

Creating database applications in C# is a breeze, but I'm up to my
knees in questions about creating an application which stores its data
in "regular record-based files"?

One simple example is that you deal with a Person structure when you
want to save a Person object to disk;

public class Person() {

private string firstname;
private string lastname;

}

When saving multiple records of the above structure to disk, each
record will have varying length depending on the length of the two
strings.

That might be nice if you're always referring to Person() objects in
list context (ie. saving all of them every time), but not when you're
dealing with only _one_ record.

Any suggestion on how to solve this?
 
Did you try serialization? Since you need to store only one record, you
just have to make your Person class serializable by using the
Serializable arrtibute and then store it into ur file.

Check out this MSDN link:
ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpovrserializingobjects.htm

HTH,
fbhcah
 
Did you try serialization?

I have just had a brief look at it, but I really don't know if that'll
do it for me. Let's say that I have an application which displays a
list (ListBox) with Person objects. That list of Person objects is in
turn handled by a PersonList object (which derives from an ArrayList);

public class PersonList : ArrayList {

publish PersonList() {
}

}

public class Person {

private string firstname;
private string lastname;

public Person() {
}

public Person( string fname, string lname ) {
this.firstname = fname;
this.lastname = lname;
}

public string Firstname {
get {
return this.firstname;
}
set {
this.firstname = value;
}
}

public string Lastname {
get {
return this.lastname;
}
set {
this.lastname = value;
}
}

}

Would it be possible to create an instance of PersonList in my
application and set the ListBox's DataSource property to that list and
have it update itself every time I do an Add() to the PersonList
object? Or do I have to Add() to the ListBox object all the way?
 
Back
Top