Passing an Access wildcard from VB.Net 2005
-
I am working wiht VB.Net 2005 and I am looking at an Access 2003 database. I can run a Delte query in Access and it works fine. But when I try to run the same query from my program it doesn't delete anything. Can someone tell me what I doing wrong? Thanks so much for your help with this.... Cursor = System.Windows.Forms.Cursors.WaitCursor 'Build SQL to delete this department Dim TempDepartNum As String = Me.txtDepartNum.Text Dim Sql As String = String.Empty 'initialize database connection Dim Connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Databases\Converted to 2003\C022008.mdb") 'set up SQL command to delete records 'DELETE SHACT.ActAcct, *FROM(SHACT) WHERE (((SHACT.ActAcct) Like '100*')); Sql = "DELETE * FROM SHACT WHERE (((SHACT.ActAcct) Like '100*'));" Try 'connect to the database and delete the records Connection.Open() Dim Command As New OleDbCommand(Sql, Connection) Command.ExecuteNonQuery() MessageBox.Show("Delete Department function completed successfully.", "Delete", MessageBoxButtons.OK)
-
I am working wiht VB.Net 2005 and I am looking at an Access 2003 database. I can run a Delte query in Access and it works fine. But when I try to run the same query from my program it doesn't delete anything. Can someone tell me what I doing wrong? Thanks so much for your help with this.... Cursor = System.Windows.Forms.Cursors.WaitCursor 'Build SQL to delete this department Dim TempDepartNum As String = Me.txtDepartNum.Text Dim Sql As String = String.Empty 'initialize database connection Dim Connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Databases\Converted to 2003\C022008.mdb") 'set up SQL command to delete records 'DELETE SHACT.ActAcct, *FROM(SHACT) WHERE (((SHACT.ActAcct) Like '100*')); Sql = "DELETE * FROM SHACT WHERE (((SHACT.ActAcct) Like '100*'));" Try 'connect to the database and delete the records Connection.Open() Dim Command As New OleDbCommand(Sql, Connection) Command.ExecuteNonQuery() MessageBox.Show("Delete Department function completed successfully.", "Delete", MessageBoxButtons.OK)
Try changing the wild card * in your LIKE statement to a % see if that works. IE: Like '100*')); changes to Like '100%'));
-
Try changing the wild card * in your LIKE statement to a % see if that works. IE: Like '100*')); changes to Like '100%'));