Trouble with Insert into selected table function

Hi I am struggling with an insert statement which is used to insert values into the table which is selected from a drop downlist.

I have included my code below which takes the input of a dictionary values indexed by the column names and a string representing the table name. returning a boolean to indicate the status of the insert

But am unsure of where I am going wrong in terms of the code, as I think that it's along the right lines.

Any tips would be great please.

 public bool Insert(Dictionary<string, string> values, string tableName) { SqlDataAdapter adapter; using (SqlConnection conn = new SqlConnection(ConnectionString)) { string query = "INSERT INTO" tableName "VALUES({string.Join("," values)})"; using (SqlCommand command = new SqlCommand(query, conn)) { conn.Open(); adapter = command.ExecuteAdapter(); } } return adapter; } } } 

by billytheone via /r/csharp

Leave a Reply