Candle Serie + DBNull in dataset

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
ACTL
Newbie
Newbie
Posts: 14
Joined: Thu Sep 30, 2004 4:00 am

Candle Serie + DBNull in dataset

Post by ACTL » Wed Jan 04, 2006 5:43 pm

Hello,

When I associate a Candle serie to a dataset with NULL rows (See example below) then I receive the error "Object cannot be cast from DBNull to other types".
Can you tel me How to manage that.

Thanks in advance.

Sample code:

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim DataSet_Obj As New DataSet
Dim DataRow_Obj As DataRow

Dim Tag_Serie_Candle As Steema.TeeChart.Styles.Candle

DataSet_Obj.Tables.Add("CandleTable")
DataSet_Obj.Tables("CandleTable").Columns.Add( _
New DataColumn("Date", System.Type.GetType("System.DateTime")))
DataSet_Obj.Tables("CandleTable").Columns.Add( _
New DataColumn("Open", System.Type.GetType("System.Double")))
DataSet_Obj.Tables("CandleTable").Columns.Add( _
New DataColumn("Close", System.Type.GetType("System.Double")))
DataSet_Obj.Tables("CandleTable").Columns.Add( _
New DataColumn("High", System.Type.GetType("System.Double")))
DataSet_Obj.Tables("CandleTable").Columns.Add( _
New DataColumn("Low", System.Type.GetType("System.Double")))

DataRow_Obj = DataSet_Obj.Tables("CandleTable").NewRow()
DataRow_Obj("Date") = CDate("01/01/2005 10:00:00")
DataRow_Obj("Low") = 100
DataRow_Obj("Close") = 110
DataRow_Obj("Open") = 120
DataRow_Obj("High") = 130
DataSet_Obj.Tables("CandleTable").Rows.Add(DataRow_Obj)
DataRow_Obj = Nothing

DataRow_Obj = DataSet_Obj.Tables("CandleTable").NewRow()
DataRow_Obj("Date") = CDate("01/01/2005 10:10:00")
' SIMULATE NULL VALUES
DataSet_Obj.Tables("CandleTable").Rows.Add(DataRow_Obj)
DataRow_Obj = Nothing

DataRow_Obj = DataSet_Obj.Tables("CandleTable").NewRow()
DataRow_Obj("Date") = CDate("01/01/2005 10:20:00")
DataRow_Obj("Low") = 120
DataRow_Obj("Close") = 130
DataRow_Obj("Open") = 140
DataRow_Obj("High") = 150
DataSet_Obj.Tables("CandleTable").Rows.Add(DataRow_Obj)
DataRow_Obj = Nothing

Tag_Serie_Candle = New Steema.TeeChart.Styles.Candle
TChart1.Series.Add(Tag_Serie_Candle)

Tag_Serie_Candle.DataSource = DataSet_Obj.Tables("CandleTable")
Tag_Serie_Candle.OpenValues.DataMember = DataSet_Obj.Tables("CandleTable").Columns("Open").ToString()
Tag_Serie_Candle.CloseValues.DataMember = DataSet_Obj.Tables("CandleTable").Columns("Close").ToString()
Tag_Serie_Candle.DateValues.DataMember = DataSet_Obj.Tables("CandleTable").Columns("Date").ToString()
Tag_Serie_Candle.DateValues.DateTime = True
Tag_Serie_Candle.HighValues.DataMember = DataSet_Obj.Tables("CandleTable").Columns("High").ToString()
Tag_Serie_Candle.LowValues.DataMember = DataSet_Obj.Tables("CandleTable").Columns("Low").ToString()
Tag_Serie_Candle.LabelMember = "Test ACTL"
Tag_Serie_Candle.CheckDataSource()

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Thu Jan 05, 2006 8:33 am

Hello,

There are two ways round this: you can either set your null values to zero, e.g.:

Code: Select all

  DataRow_Obj = DataSet_Obj.Tables("CandleTable").NewRow()
        DataRow_Obj("Date") = CDate("01/01/2005 10:10:00")
        ' SIMULATE NULL VALUES
        DataRow_Obj("Low") = 0
        DataRow_Obj("Close") = 0
        DataRow_Obj("Open") = 0
        DataRow_Obj("High") = 0
        DataSet_Obj.Tables("CandleTable").Rows.Add(DataRow_Obj)
        DataRow_Obj = Nothing
Or you can use the technique outlined in the feature demo under:
Welcome !\Chart styles\Financial\Candle (OHLC)\Axis Labels no Weekends
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

Post Reply