Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.net with Access SQL

Posted on 2011-03-23
3
Medium Priority
?
293 Views
Last Modified: 2012-06-27
Hi

How do I update the SQL statement in the following code:
SELECT DISTINCT [Subject or activity] FROM [Table1]
so that nulls are not included.
Sub LoadSubjectDropDown()
        '// define a connection to the database
        Dim cs As String = ConfigurationManager.ConnectionStrings("WhatEverNameYouWant").ConnectionString
        cs = cs.Replace("App_Data\GC.accdb", Server.MapPath("App_Data\GC.accdb"))

        Dim cn As New OleDbConnection(cs)
        Try
            '// define the sql statement to execute
            Dim cmd As New OleDbCommand("SELECT DISTINCT [Subject or activity] FROM [Table1]", cn)
            '// open the connection
            cn.Open()
            '// execute the sql statement
            Using reader As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
                DropDownList_Subject.DataSource = reader
                DropDownList_Subject.DataValueField = "Subject or activity"
                DropDownList_Subject.DataTextField = "Subject or activity"
                DropDownList_Subject.DataBind()
            End Using
        Catch ex As Exception
            Response.Write(ex.Message)

        Finally
            If cn.State <> ConnectionState.Closed Then
                cn.Close()
            End If
        End Try
    End Sub

Open in new window

0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 35199281
try

"SELECT DISTINCT [Subject or activity] FROM [Table1] Where [Subject or activity] <> Null"

or

"SELECT DISTINCT [Subject or activity] FROM [Table1] Where [Subject or activity] is not Null"
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 2000 total points
ID: 35199290
or

"SELECT DISTINCT [Subject or activity] FROM [Table1] Where [Subject or activity] & "" <> """
0
 

Author Closing Comment

by:Murray Brown
ID: 35199454
thanks very much
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question