oledbcommand.ExecuteNonQuery()

I am using a Access mdb file. I want to insert the selected records into the same table of another mdb file. So I use oledbcommand.executenonquery().

my sql query is "Insert into TBContacts in 'c:\tb.mdb' select * from TBContacts where FromID like 'AP2007-02-26-*' "

when I use executenonquery() , it doesn't work, and no any error exists.

and I try to remove where cluse, it works fine? why? any kind of solution allows me to insert records against the where cluse? thank you

[516 byte] By [yhong] at [2008-1-10]
# 1

I have never seen valid SQL that allowed you to specify a database file right in the insert like that.

why not add the TBContacts table from the one DB into the other as a linked table. Then you could create a query in access to append records from one table to another. Then you would just call that query from code instead of an insert.

kleinma at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
I know your way, but right now I need this kind of solution, by the way, how do I use "Select into" in oledbcommand? honestly, ado.net is much harder than adodb.
yhong at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

Hi Yhong,

Based on your post, my understanding of your question is that you need to manipulate the different databases. When you create two Connection object, then you can permit a single Command to be executed against different database instances with the same schema.

In this scenario you can set the Command's Connection using the Connection property instead of passing it in as a constructor parameter. A Connection can have many Commands, but a Command is associated only with a single Connection at a time. So you can't execute one Command to manipute the different databases. The Connection can be changed at any time. This capability is useful when the data in a series of tables is spread across multiple database instances. Hope this helps.

Best regards,

Riquel.

RiquelDong–MSFT at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic Language...