A code sample in Listing 6.2 of Scott Mitchell's book Asp.net Data Web
Controls shows how to generate a dynamic sql statement with a WHERE
clause based on a button that the user clicks. It is based on the Sql
Server's Pubs database and everything works fine, but when I changed
it to DB2 and modified the associated code (connecting now via ODBC so
all the Sql* became Odbc*), the dynamic sql doesn't work anymore
(gives no error message; it displays table headers but gives no data)
although my static sql statement (when filterValue = String.Empty)
still works. Below is my code. I am wondering if the symbol in the
dynamic WHERE clause works for Sql servers only. Does anyone have any
idea? Please help!

************************************************** ***

<% import Namespace="System.Data" %>
<% import Namespace="System.Data.Odbc" %>
<script runat="server" language="VB">

Sub Page_Load(sender as Object, e as EventArgs)
If Not Page.IsPostBack then
End If
End Sub

Sub BindData(filterValue as String)

'1. Create a connection
Const strConnString as String = "DSN=myDsn;UID=myId;PWD=myPwd;"
Dim objConn as New OdbcConnection(strConnString)

'Create an appropriate SQL command string
Dim strSQL as String
If filterValue = String.Empty then
strSQL = "SELECT lname, fname FROM books WHERE publisher = 'sams'"
'SQL needs WHERE clause
strSQL = "SELECT lname, fname, FROM books WHERE publisher = 'sams'
AND 'category'"
End If

'2. Create a command object for the query
Dim objCmd as New OdbcCommand(strSQL, objConn)

'Add parameter for WHERE clause if needed
If strSQL <> String.Empty then
Dim filterParam as New OdbcParameter("category", OdbcType.Char,
filterParam.Value = filterValue
End If


'Finally, specify the DataSource and call DataBind()
dgTitles.DataSource =
objCmd.ExecuteReader(CommandBehavior.CloseConnecti on)

End Sub

Sub FilterData(sender as Object, e as CommandEventArgs)
End Sub

Sub DisplayViewingTypeMessage(filterValue as String)
If filterValue = String.Empty then
lblViewingMsg.Text = "You are viewing all categories published by
lblViewingMsg.Text = "You are viewing only this category - " &
End If
End Sub


<form runat="server">
<asp:Button Text="View ALL category" runat="server"
CommandArgument="" OnCommand="FilterData" />
<asp:Button Text="View Computer" runat="server"
CommandArgument="Computer" OnCommand="FilterData" />
<asp:Button Text="View Fiction" runat="server"
CommandArgument="Fiction" OnCommand="FilterData" />
<asp:Button Text="View Non-Fiction" runat="server"
CommandArgument="NonFiction" OnCommand="FilterData" />

<p><asp:label id="lblViewingMsg" runat="server" /></p>

<asp:DataGrid runat="server" id="dgTitles"
<HeaderStyle BackColor="#ddddff" HorizontalAlign="Center" />
<AlternatingItemStyle BackColor="#eeeee6" />
<asp:BoundColumn DataField="lname" HeaderText="Last Name" />
<asp:BoundColumn DataField="fname" HeaderText="First Name" />
<asp:BoundColumn DataField="category" HeaderText="Category" />