I get Invoices from a WebApi and I insert these Invoices into a SQL table. I use C# to do this operation. I use System.Data.SqlClient where I generate this SQL query:
string sql = String.Format("insert into [dbo].[InvoiceHeader] values('{0}','{1}','{2}','{3}')", inv.logNo, inv.locationCode, inv.invSeq,inv.reference);
command = new SqlCommand(sql, cnn);
adapter.InsertCommand.ExecuteNonQuery();
The problem is that one of the Invoices has an inv.reference = "Box 20' Cont" and that ' is a problem for the InsertCommand. How do I insert text into a sql database when the variable contains an ' in the text?.