How to write to and read from a database?

Table-valued functions in finaquant .net libraries

How to write to and read from a database?

Postby savior » 07 Jan 2014, 20:45

How can i read or write tables to a database with finaquant's table functions?
thanks, Savior
Posts: 1
Joined: 07 Jan 2014, 20:43

Re: How to write to and read from a database?

Postby finaquant » 15 Jan 2014, 21:31

You can use corresponding read/write methods of classes DataStore or PersistentTableArray of finaquant libraries (finaquant® protos or finaquant® calcs) for reading or storing data tables.

An example with DataStore:

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. // Connection string for database (replace with your own)
  2. String ConnStr = @"Data Source=.\SQLEXPRESS;AttachDbFilename="
  3.   + ProjectPath + @"\Databases\finaquantdb.mdf;Integrated Security=True;User Instance=True";
  4. string DataProvider = "System.Data.SqlClient";
  6. // init DataStore
  7. DataStore dstore = new DataStore(DataProvider );
  9. // open database connection
  10. dstore.OpenConnection(ConnStr);
  12. // Create instance information (table row)
  13. TableRow trow1 = TableRow.CreateTableRowWithElements(InstanceTblFields,
  14.     "Peru", 1984);
  16. // write instance (trow1) of table CostTable into table named "cost_table" in database
  17. dstore.WriteTableInstance(CostTable, "cost_table", trow1);
  19. // close database connection
  20. dstore.CloseConnection();
GeSHi ©

Note that, with finaquant's table functions you can only read and write tables as a whole; you can't update for example a table only partially in a database. That is, CostTable1 will be overwritten by CostTable2 in the following example:

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. // write CostTable1 into db table with instance trow1
  2. dstore.WriteTableInstance(CostTable1, "cost_table", trow1);
  4. // write CostTable2 into db table with instance trow1
  5. dstore.WriteTableInstance(CostTable2, "cost_table", trow1);
GeSHi ©

You can find more information about reading or storing data tables in our related article: Persistent Table Array

You can also find examples in the downloadable Visual Studio projects with Demo Functions for Getting Started; see related downloads at finaquant® protos (non-commercial) or finaquant® calcs (commercial).

User avatar
Posts: 61
Joined: 16 Sep 2013, 18:37

Return to Table Functions

Who is online

Users browsing this forum: No registered users and 1 guest