Dataset Question

Using VB VSE I created a dataset and included some fields which were calculated. For example:

FldA - Single
FldB - Single
FldC - (FldA + FldB)

When I try to populate a new row I thought I'd be able to set FldA to something like 3.4 and FldB to 4.4 and the value of FldC would automatically be saved as 7.8 When I rty to save the row I get an error that FldC is Null and cannot be saved. How am I supposed to use calculated columns in this type of situation


Answer this question

Dataset Question

  • GenericMoniker

    Carl;

    Thanks for the response. I setup my calculated fields using the GUI. I'll try it in code as you show.

  • hewin

    WayneW,

       When I try this I don't get an exception.  I get the value 7.8 for column 3 of the DataTable.  I've pasted an example bleow that shows this behavior and the MessageBox shows 7.8.  Is this the same repro code as yours

    Dim ds As New DataSet()

    Dim dt As New DataTable()

    dt.Columns.Add(New DataColumn("FldA", Type.GetType("System.Single")))

    dt.Columns.Add(New DataColumn("FldB", Type.GetType("System.Single")))

    dt.Columns.Add(New DataColumn("FldC", Type.GetType("System.Single")))

    dt.Columns(2).Expression = "FldA + FldB"

    dt.Rows.Add(3.4, 4.4)

    MessageBox.Show(dt.Rows(0)(2).ToString())

    Carl Perry
    Program Manager ADO.NET
    cperry@microsoft.com



  • Dataset Question