|
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.
|
|
|
|