1

I had try to delete a row in a table using the following code, but I got an error.

{System.Data.OleDb.OleDbException: Missing ), ], or Item in query expression 
'[CompanyID] not in (Select [CompanyID] from EmployeeDetails 
where [CompanyID] = @cmpID'.

Here is my code:

int companyID = _cmpDetailsList[i].CompanyID;        
OleDbCommand upcmd = new OleDbCommand(
    "delete * from CompanyDetails where [CompanyID] not in " + 
    "(Select [CompanyID] from EmployeeDetails where [CompanyID] = @cmpID", conn);
conn.Open(); 
upcmd.Parameters.AddWithValue("@cmpID", companyID);
upcmd.ExecuteNonQuery();
conn.Close();

i modified the command to in this format

OleDbCommand upcmd = new OleDbCommand("delete * from CompanyDetails where [CompanyID]= @cmpID and not in (Select [CompanyID] from EmployeeDetails where [CompanyID] = @cmpID)", conn);

i got the following error

System.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression '[CompanyID]= @cmpID and not in (Select [CompanyID] from EmployeeDetails where [CompanyID] = @cmpID)'.

please solve it

1
  • 3
    it works for the case Select * for delete its the entire row so just delete from ... Commented Jun 6, 2013 at 7:11

1 Answer 1

9

If you read the error, it tells you the problem:

OleDbCommand upcmd = new OleDbCommand(
"delete from CompanyDetails where [CompanyID] not in " + 
"(Select [CompanyID] from EmployeeDetails where [CompanyID] = @cmpID)", conn);

You had a ( but no matching ) at the end.

Sign up to request clarification or add additional context in comments.

2 Comments

delete * from is valid for access...not sure what the op is using though
+1 One more thing if you could add is the usage of @ string literal which would have made the query easier to read and spot the missing braces, the good thing is OP using parameters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.