sql - Generic function to append data into MS Access table using C# -


i have written function supposed insert 3 items ms access table using c#:

      public static void appenddatatotable(string connectionstring, string tablename, string[] headers, string[] values)     {              var myconn = new oledbconnection(connectionstring);              var cmd = new oledbcommand("insert into" + tablename +" (x, y, z) values (@x, @y, @z)");             cmd.parameters.addrange(new[] { new oledbparameter(headers[0], values[0]), new oledbparameter(headers[1], values[1]), new oledbparameter(headers[2], values[2]) });             myconn.open();             cmd.executenonquery();             myconn.close();      } 

first, there seems mistake , cannot figure out what?

second, possible make generic function if have 10 columns still works , dynamically resizes headers.length?

thanks!

you not use sqlconnection / sqlcommand connect msaccess. use oledbconnection. correct , should work. can take of this link more information.

you need make query of type can accept upto 10 column names. need write own logic that.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -