Click here to Login





                                                   Adding data to database through script

  0

0
Obuli Govindaraju
2012-01-02 22:25:13


To add data to a database through a script I need to use DatabasesData along with Databases.SaveDatabaseData method.

So how do I add values to the DatabasesData? For example the code below throws an error."A readonly field cannot be assigned to (except in a constructor or a variable initializer)"

DatabasesData dbaseData;
Chart chart = Charts.GetSelectedChart();
ChartData chartData = chart.ChartData;
dbaseData.Symbol = chart.SymbolName;



QuantShare
2012-01-03 05:03:35

  0

You should get a "DatabasesData" object using:

DatabasesData data = Databases.GetDatabasesData("Symbol Name", "MyDatabase", "MyField");

After that, you can update/add content by modifying:

data.Date
data.Value

Finally, you can save the data using:

Databases.SaveDatabasesData(data);



Obuli Govindaraju
2012-01-03 22:21:13

  0

ok, I get the concept. However how do I add something new to an empty database.

for example I get an error for the following code

data.Date = DateTime.Parse("1/1/1980");
data.Value = 56.78;

Error(s)
Cannot implicitly convert type 'System.DateTime' to 'System.DateTime[]'
Cannot implicitly convert type 'double' to 'object[]'



QuantShare
2012-01-04 05:54:14

  0

Best Answer
In a new database, the arrays "data.Date" and "data.Value" are empty.

Here is how to add an entry:

data.Date = new DateTime[1];
data.Value = new Object[1];

data.Date[0] = DateTime.Parse("1/1/1980");
data.Value[0] = 56.78;




Obuli Govindaraju
2012-01-04 06:25:53

  0

ok Thanks!

I got couple of more questions.

How is the array indexed meaning is the last row in the database indexed as 0 or first row as 0?

And second if a database has 2 fields do I have to provide date for both the fields or just one is enough?



QuantShare
2012-01-04 10:15:37

  0

The first row has the zero index.

If the database has two fields then you should call "Databases.GetDatabasesData" twice (once for each field) and then update the "Date" and "Value" array of each one.



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
Lagged Data From a Custom Database
Historical EOD data Downloader for Delisted/Bankrupt Stocks
Survivorship bias-free S&P 500 database downloader
Euronext Paris - Realtime Share Prices Data
EOD NSE stock quotes data

How-to Lessons
How to use QuantShare with Metastock data
How to quickly download the most recent EOD data for your stocks
How to download and use U.S. stocks earnings data
How to export trading data to a CSV file
How to get stocks for a particular index using the global script

Related Forum Threads
Is it possible to delete database data through a script?
Can I update the sector and industry information in the stock dat...
Clear Symbol data stored in memory in global script
Data Interpolation c# Script
Deleting Data From The Database

Blog Posts
Speed Up Optimizations by Saving Ranking Data into a Custom Datab...
How to filter quotes data from high and low price spikes
4 Market Composite Indicators Based on Industry Data
Trading Items: Data Download using .Net Scripts
Step by step on how to get free realtime/delayed data for stocks,...









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.