none
"WHERE" Clause of SQL in DataAdapter not giving due results. RRS feed

  • Question

  • ReleaseOrdersConnection = New OleDbConnection(sReleaseOrdersConnectionStr)
    ReleaseOrdersConnection.Open()
    tSqlString = "SELECT * FROM [Orders$] WHERE Status NOT LIKE " & """" & "Released" & """" '
    ReleaseOrdersDataAdapter = New System.Data.OleDb.OleDbDataAdapter(tSqlString, ReleaseOrdersConnection)
    ReleaseOrdersDtSet = New System.Data.DataSet
    ReleaseOrdersDataAdapter.Fill(ReleaseOrdersDtSet, 1, MaxNumberOfRecordsinXlsx, "ReleaseOrders")
    The Above code is not working.  Where is the fault? Thank you.
    Thursday, July 9, 2015 3:15 PM

Answers

  • Thanks for all the Answers. But the Statement I posted is correct. The fault lies in the MS Excel.

    You can not apply 'NOT' Clause of SQL Statement on MS Excel directly.

    I home MS is reading this to make amends to MS Excel.

    Thanks Once Again.

    • Marked as answer by RakLali Saturday, August 8, 2015 9:44 AM
    Saturday, August 8, 2015 9:44 AM

All replies

  • ReleaseOrdersConnection = New OleDbConnection(sReleaseOrdersConnectionStr)
    ReleaseOrdersConnection.Open()
    tSqlString = "SELECT * FROM [Orders$] WHERE Status NOT LIKE " & """" & "Released" & """" '
    ReleaseOrdersDataAdapter = New System.Data.OleDb.OleDbDataAdapter(tSqlString, ReleaseOrdersConnection)
    ReleaseOrdersDtSet = New System.Data.DataSet
    ReleaseOrdersDataAdapter.Fill(ReleaseOrdersDtSet, 1, MaxNumberOfRecordsinXlsx, "ReleaseOrders")
    The Above code is not working.  Where is the fault? Thank you.
    Thursday, July 9, 2015 3:13 PM
  • "SELECT * FROM [Orders$] WHERE Status NOT LIKE " & """" & "Released" & """" '

    is not valid T-SQL. Use single quotes instead.

    "SELECT * FROM [Orders$] WHERE Status NOT = '" & "Released'"

    Thursday, July 9, 2015 6:08 PM
  • I think it would help to know exactly what you're looking for. Is it NOT LIKE 'Released' or is it NOT LIKE '%Released%'  or something else entirely? It's not clear from your attempted code what the actual query is supposed to be. And I don't see why you're concatenating strings with & ... why bother will all that, just write it like this:

    "SELECT * FROM [Orders$] WHERE Status NOT LIKE 'Released'  "

    Unless that's not what you're trying to accomplish ... so, could you clarify?


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Friday, July 10, 2015 4:58 AM
  • Thanks for all the Answers. But the Statement I posted is correct. The fault lies in the MS Excel.

    You can not apply 'NOT' Clause of SQL Statement on MS Excel directly.

    I home MS is reading this to make amends to MS Excel.

    Thanks Once Again.

    • Marked as answer by RakLali Saturday, August 8, 2015 9:44 AM
    Saturday, August 8, 2015 9:44 AM