DataTable Demo Using the Expression Property

This demo illustrates creating a computed column using the Expression property. Here, we add a column to the DataTable titled Future Views, whose value is computed as the value of the ViewCount column multiplied by 1.1.


FAQIDDescriptionViewCountFAQCategoryIDSubmittedByNameSubmittedByEmailDateEnteredCatNameFuture Views
181How can I format numbers and date/times using ASP.NET? For example, I want to format a number as a currency.90123222Scott Mitchellmitchell@4guysfromrolla.com1/19/2002 3:12:07 PMASP.NET991355
161How can I convert a Recordset into an array? Also, how can I convert an array into a Recordset?2193341Scott Mitchellmitchell@4guysfromrolla.com6/14/2001 5:02:02 PMArrays241267
115I am using Access and getting a 80004005 error (or a [Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot open the file '(unknown)' error) when trying to open a connection! How can I fix this problem?21769421Scott Mitchellmitchell@4guysfromrolla.com1/17/2001 11:38:49 PMDatabases, Errors239463
83How can I quickly sort a VBScript array? 2121451Richard Lowechadich@yahoo.com11/12/2000 1:58:41 AMArrays233360
190How do I display data on a web page using arrays instead of Do...While...MoveNext...???...1680931Scott Mitchellmitchell@4guysfromrolla.com4/11/2002 1:14:41 PMArrays184902
106How can I find out if a record already exists in a database? If it doesn't, I want to add it.16751312Steve Ciminosteve_cimino@hotmail.com12/14/2000 4:59:11 PMDatabases, Queries184264
118When I get a list of all files in a directory via the FileSystemObject, they aren't ordered in any reasonable way. How can I sort the files by name? Or by size? Or by date created? Or... 1518504Bill Wilkinsonbill@ClearviewDesign.com1/22/2001 5:10:01 PMFileSystemObject167035
30For session variables to work, must the Web visitor have cookies enabled?1181416Scott Mitchellmitchell@4guysfromrolla.com9/26/2000 11:13:06 PMSession Object129955
14Can I send emails without using CDONTS?11508910Scott Mitchellmitchell@4guysfromrolla.com9/24/2000 1:18:37 AMEmail126598
153How can I take the result of a SELECT...MULTIPLE or a group of same-named checkboxes and turn it into a query? That is, if the user selects 3 answers, how can I construct a query that looks for all 3?11362112Bill Wilkinsonbill@ClearviewDesign.com4/19/2001 3:15:34 PMDatabases, Queries124983


Source Code

<%@ Import Namespace="System.Data" %>
<script language="VB" runat="server">
  Sub Page_Load(sender as Object, e as EventArgs)
    If Not Page.IsPostBack then
      'Create the DataTable
      Dim dt as New DataTable()
     
      Dim myConnection as New SqlConnection(Connection String)
    
      Const strSQL as String = "sp_Popularity"
      Dim myCommand as New SqlCommand(strSQL, myConnection)

      Dim myAdapter as New SqlDataAdapter(myCommand)
      myAdapter.Fill(dt)

      Dim dcFutureViews as New DataColumn("Future Views", GetType(Integer))
      dcFutureViews.Expression = "ViewCount * 1.1"
      dt.Columns.Add(dcFutureViews)
     
      
      'Bind the DataTable to the DataGrid
      dgPeople.DataSource = dt
      dgPeople.DataBind()
    End If      
  End Sub
</script>

<asp:DataGrid runat="server" id="dgPeople"
	HeaderStyle-BackColor="LightGray"
	HeaderStyle-Font-Bold="True" />


[Return to the article...]