Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Queries for Access db connection not working in VB.NET

Status
Not open for further replies.

plocks

Programmer
Aug 26, 2011
16
US
My code below executes a SELECT...INTO...FROM query using an Access connection. If I run the SQL directly in Access, it works perfectly. If it runs in VB, it creates the new table but does not populate it.

I've tried creating the table then using an INSERT INTO statement to supply the data, but that is not working either in VB.

Both ways do not throw any errors. ExecuteNonQuery is returning 0 rows affected.

If anyone can supply any help it would be greatly appreciated. I'm pulling what's left of my hair straight out of my head!


Code:
        Dim check As Integer

        Dim accessPath As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source = " & _
        "C:\Users\Desktop\CustomersInformation.mdb;"
        Dim Conn As New System.Data.OleDb.OleDbConnection
        Conn = New System.Data.OleDb.OleDbConnection(accessPath)
        Conn.Open()

        Dim Cmd As System.Data.OleDb.OleDbCommand

        '...

        Dim SQL As String = "SELECT CustomerShipTo.[Name], CustomerShipTo.[CustomerID] INTO Temp_PriorityShipping_T " _
        & "FROM CustomerShipTo GROUP BY CustomerShipTo.[Name], CustomerShipTo.[CustomerID] " _
        & "HAVING (((CustomerShipTo.[Name]) Like '*world*'"
        Cmd = New System.Data.OleDb.OleDbCommand(SQL, Conn)
        Try
            check = Cmd.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
            Exit Sub
        End Try

        Conn.close()

To note: Where you see '..., there is a bunch of other SQL statements (some that are SELECT...INTO...FROM's) and they all work perfectly. This is the only time an append statement will not work.
 
Found the error!

My LIKE statement needed % as wildcards and not the *.

Like '%world%' makes it work!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top