Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse IIF in a SQL SELECT statement to make a DataReport display a warning if a value is too low in VB.NET
DescriptionThis example shows how to use IIF in a SQL SELECT statement to make a DataReport display a warning if a value is too low in VB.NET.
KeywordsDataReport, VB.NET, IIF, warning, CrystalReportViewer, CrystalReport, CrystalReports
CategoriesVB.NET, Database, Controls
 
Create an OleDbDataAdapter. Use the DataAdapter Configuration Wizard to configure the adapter. This builds a database connection for the adapter and defines the SQL query used to select data.

Select the adapter. Below the Properties window, click the "Generate DataSet" link.

Select the Project menu's Add New Item command and add a Crystal Report to the project.

In the Standard Report Expert's "Available data sources" list, select:

    Project Data
        ADO.NET DataSets
            howto_net_data_report_iif.StudentsDataSet
                Students

Then click the Insert Table button to select it. Click Next.

Add all of the selected fields to the display list.

Click the Formula button. Enter Warning as the formula's name. In the Formula Editor, enter:

    Formula = IIF({Students.Score} < 75, "!", "")

Put a CrystalReportViewer control on the form.

When you run the program, if a database login dialog appears, cancel it.

 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    ' Fill the DataSet.
    daStudents.Fill(dsStudents)

    ' Make a report and bind the DataSet to it.
    Dim rpt As New CrystalReport1
    rpt.SetDataSource(dsStudents)

    ' Bind the viewer to the report.
    CrystalReportViewer1.ReportSource = rpt
End Sub
 
For more information on database programming in VB .NET, see my book Visual Basic .NET Database Programming.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated