Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add expression column

Status
Not open for further replies.

vwalla

Technical User
Feb 25, 2004
22
US
Is there anything qrong with this code?

Code:
Sub showExtended()
        Dim dcTotal As New Data.DataColumn("totalPrice", System.Type.GetType("System.Decimal"))
        dcTotal.Expression = "PriceEach * QTY"
    End Sub

My load event

Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DatagridDataSet.tblData' table. You can move, or remove it, as needed.
        Me.TblDataTableAdapter.Fill(Me.DatagridDataSet.tblData)
        showTotal()
        showExtended()
    End Sub

I do not get any errors when placed in the formLoad event, but there is also no "computed" value in the column for the rows.

I am using vb 2005 express.

Thanks
 
you need to add the column to your dataset for it to work

Code:
Sub showExtended()
        Dim dcTotal As New Data.DataColumn("totalPrice", System.Type.GetType("System.Decimal"))
        dcTotal.Expression = "PriceEach * QTY"
        me.datagriddatasettables(0).columns.add(dctotal)
    End Sub

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
I get the following error:

"Object reference not set to an instance of an object."

??

Thanks
 
this

me.datagriddatasettables(0).columns.add(dctotal)

should be

me.datagriddataset.tbldata.columns.add(dctotal)


Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Getting same error.

"Object reference not set to an instance of an object."

I am at a loss.

Thanks
 
where do you get the error.

if you do a watch wich of the objects is nothing.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
This is where the error is.

Code:
Me.DatagridDataSet.Tables(0).Columns("totalPrice").Expression = "PriceEach * QTY"

The exception is "NullReferenceException was Unhandled"

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top