Click here to Login

Trading Software Trading objects Features How-to Blog Search


                                                   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
EOD NSE stock quotes data
Daily Stock Quotes - Stock Market EOD Data
Bourse de Tunis - EOD data
Bursa Malaysia EOD data

How-to Lessons
How to quickly select stocks based on the last value of a databas...
How to download and use U.S. stocks earnings data
How to download Portfolio123 data into QuantShare
How to export trading data to a CSV file
How to get stocks for a particular index using the global script

Related Forum Threads
Can I update the sector and industry information in the stock dat...
Deleting Data From The Database
Plot through the script editor
How to view the raw data files?
Downloading Mutual fund data

Blog Posts
How to filter quotes data from high and low price spikes
QS Trading Software: Database Optimization
QS Trading Software: Global Script
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 © 2012 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items