array insert in db

Posted by gloris on Stack Overflow See other posts from Stack Overflow or by gloris
Published on 2010-03-28T19:31:43Z Indexed on 2010/03/28 19:43 UTC
Read the original article Hit count: 222

Filed under:
|
|
|

Hi,

How best to put the array (100 or more length) in the database (MySQL)?

I do not want multiple access to the database because it is so loaded.

So my solution is as follows:

string insert = "INSERT INTO programs (name, id) VALUES ";

        for(int i = 0; i < name.Length; i++)
        {
            if (i != 0)
            {
                insert = insert + ",(";
            }
            else
            {
                insert = insert + "(";
            }

            insert = insert + "'" + name[i] + "','" + id[i] + "'";

            insert = insert + ")";
        }

        //INSERT INTO programs (name, id) VALUES ('Peter','32'),('Rikko','343') ....

But maybe is a faster version?

Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about mysql