c# - Insert multiple row using the same MySQL connection? -
i wondering how can insert multiple rows mysql database using 1 connection instead of opening , closing multiple connections. data being inserted coming string[] used foreach loop each value.
here current non-working c# code:
string[] tempfin = table.split(','); string username = null; connection.open(); foreach (object hope in tempfin) { command.commandtext = "insert atable (tried, username) values" + "('" + hope + "','" + username + "')"; command.executereader(); } connection.close();
i open , close connection in foreach loop has been proven unreliable me when inserting large amounts of rows, there way insert multi rows using 1 connection in c#?
update: never mind, found problem. using command.executereader()
instead of command.executenonquery()
the code posted using only one connection. suggest use parametrized query instead 1 using.
why isn't code working? can update question error you're getting?
if issuing insert command, should use executenonquery
instead of executereader
.
Comments
Post a Comment