Posted on: 10/23/2014 9:21:19 PM | Views : 503

Hello, I have the following code for adding a record to DB.
// //Problem Function // public static void AddRecord(string tableName, string[] columnNames, string[] newValues) { var sqlString = "insert into {0} ({1}) values ({2})"; var cols = ""; var vals = ""; for (int i = 0; i < columnNames.Length; i++) { cols = cols + "[" + columnNames[i] + "],"; vals = vals + "@" + columnNames[i] + ","; } //Remove extra commas cols = cols.Remove(cols.Length - 1); vals = vals.Remove(vals.Length - 1); using( var connection = OpenConnection()){ sqlString = string.Format(sqlString, tableName, cols, vals); var sqlCommand = ...

Go to the complete details ...