ASP.NET SQL criteria with null...can't get this to work in SQLDATASOURCE. RRS feed

  • Question

  • User240536124 posted

    OK. I haven't had to ask for help in quite some time on here, but I'm stuck. ASP.net with a SQLDATASOURCE and an MS Access Database as the db. 

    This works fine: SelectCommand="SELECT * FROM [xipam_192_168_0_x] WHERE COL2 <> Null"

    This does not: SelectCommand="SELECT * FROM [xipam_192_168_0_x] WHERE COL2 = Null"

    The Gridview I'm binding pulls up nothing. I have tried 20 different variations of matching a null and I get no data returned in any of them.

    I have tried this in the sqldatasource, as well: <asp:AccessDataSource ID="SqlDataSource3" CancelSelectOnNullParameter="False" runat="server"

    And I have tried 14 different variations of this as a parameter (for example, WHERE COL2 = @COL2): 

    <asp:SessionParameter DefaultValue="" Name="COL2" SessionField="COL2" Type="String" DefaultValue="" /> 

    My thought is that setting the DefaultValue to a null string and then having CancelSelectOnNull = False should work. I must be missing something.

    I have tried all kinds of variations in the select statement as well, such as ....OR IS NULL. Just getting nada back every time.

    This is one of the last things I need on this page, so any help would be greatly appreciated.


    Wednesday, March 7, 2018 6:05 PM


  • User240536124 posted

    Well, I swear I tried this multiple times, but I tried it one more time and it worked the first try:

    "SELECT * FROM [xipam_192_168_0_x] WHERE WHERE COL2 IS Null"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 7, 2018 8:19 PM