Ninja Database Lite
Save<T> Method
Example 



KellermanSoftware.NinjaDatabaseLite Namespace > NinjaDb Class : Save<T> Method
Save the value for the passed in key
Syntax
Public Sub Save(Of T)( _
   ByVal key As String, _
   ByVal value As T _
) 
Dim instance As NinjaDb
Dim key As String
Dim value As T
 
instance.Save(Of T)(key, value)
public void Save<T>( 
   string key,
   T value
)
public:
void Savegeneric<typename T>
( 
   String^ key,
   T^ value
) 

Parameters

key
value

Type Parameters

T
Example
//Ninja Database Lite supports any of these types
//bool, byte, decimal, double, float, int32, int64, sbyte, short, string, uint32, uint64, ulong, ushort, DateTime, 
//structs, arrays, multi-dimensional arrays, IList, IDictionary, public fields, public properties,
//Enums, timespan, GUID, double linked list and trees
 
NinjaDbConfig config = new NinjaDbConfig();
string databasePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MyApplication");
config.Storage = new FileDatabase(databasePath);
NinjaDb ninja = new NinjaDb(config);
 
//Save some simple values
ninja.Save("MyBooleanValue", true);
ninja.Save("MyDecimalValue", 19.95M);
ninja.Save("MyUrl", "http://www.kellermansoftware.com");
 
//Save an Object
Person person = new Person();
person.Name = "John";
person.PersonId = 1;
 
ninja.Save("Person1", person);
 
//Save a List of Objects
List<Person> persons = new List<Person>();
ninja.Save("PersonList", persons);
 
//Save something complex like a dictionary of lists
Dictionary<string, List<Person>> dictionaryList = new Dictionary<string, List<Person>>();
dictionaryList.Add("Customers", persons);
 
ninja.Save("PersonDictionaryList", dictionaryList);
'Ninja Database Lite supports any of these types
'bool, byte, decimal, double, float, int32, int64, sbyte, short, string, uint32, uint64, ulong, ushort, DateTime, 
'structs, arrays, multi-dimensional arrays, IList, IDictionary, public fields, public properties,
'Enums, timespan, GUID, double linked list and trees
 
Dim config As New NinjaDbConfig()
Dim databasePath As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MyApplication")
config.Storage = New FileDatabase(databasePath)
Dim ninja As New NinjaDb(config)
 
'Save some simple values
ninja.Save("MyBooleanValue", True)
ninja.Save("MyDecimalValue", 19.95D)
ninja.Save("MyUrl", "http://www.kellermansoftware.com")
 
'Save an Object
Dim person As New Person()
person.Name = "John"
person.PersonId = 1
 
ninja.Save("Person1", person)
 
'Save a List of Objects
Dim persons As New List(Of Person)()
ninja.Save("PersonList", persons)
 
'Save something complex like a dictionary of lists
Dim dictionaryList As New Dictionary(Of String, List(Of Person))()
dictionaryList.Add("Customers", persons)
 
ninja.Save("PersonDictionaryList", dictionaryList)
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

NinjaDb Class
NinjaDb Members