postgresql - Postgre SQL parametrized query for C# -


i'm trying create parametrized commad postgre in c#. goal write list of strings db table.

list<string> list = new list<string> { "listitem1", "listitem2", "listitem3" }; command.commandtext = "insert table (item) values (@listitem);"; foreach (var item in list)   {   command.parameters.addwithvalue("listitem", item);   command.executenonquery();   } 

this code finish listitem1 written in db table 3 times. guess need separate paramater name value, don't know how. help? thanks.

addwithvalue adds new parapeter on each iteration. should declare parameter once:

 list<string> list = new list<string> {     "listitem1", "listitem2", "listitem3" };   command.commandtext = "insert table (item) values (@listitem);";   // declare parameter once ...  //todo: specify parameter's value type second argument  command.parameters.add("@listitem");   foreach (var item in list) {    // ...use many    command.parameters[0].value = item;    command.executenonquery();  } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -