Multiple insert statements in single ODBC ExecuteNonQuery (C#)

后端 未结 3 998
广开言路
广开言路 2020-12-06 19:23

I\'m inserting multiple rows into a DB, and joining them together in an attempt to improve performance. I get an ODBCException telling me my SQL syntax is wrong. But when I

相关标签:
3条回答
  • 2020-12-06 19:34

    Yes, ODBC does NOT support batch processing. (EDIT: See @Jean-Do's answer for a more up to date solution.)

    But there is another option:

    1. Use the MySQL .NET Connector instead of ODBC.
    2. Then use the MySQL alternative INSERT statement: INSERT INTO test(id, name) VALUES ('1', 'Foo'), ('2', 'bar');.
    0 讨论(0)
  • 2020-12-06 19:36

    It cannot handle batching (using ; to separate multiple statements) since this would require two way communication. I am afraid you have to do it in a loop and go to database multiple times.

    In fact I have never been able to use batching with any managed provider.

    0 讨论(0)
  • 2020-12-06 19:46

    Batching is actually supported by MySQL ODBC driver v5+, you just need to click on the Details button of the ODBC control panel (if on Windows) and check the "Allow multiple statements" checkbox.

    Alternatively, uses OPTIONS=67108864 on you odbc connection string.

    More information here : http://dev.mysql.com/doc/refman/5.0/en/connector-odbc-configuration-connection-parameters.html

    0 讨论(0)
提交回复
热议问题