Hi everyone,
I'm developping an application witch allows the user to fill a form with text.
Therefore I use textboxes.
I can save the data contained in the textboxes to an Access database but there is a problem when the text contains single (') or double quotes (").
How can I solve the problem ?
Thanks
Precision : it is a desktop application WinForm in C#
What I have tried:
using Texbox1.Text doesn't work since the quotes appears in the SQL command and are interpreted as part of the command and not as data
here the code
OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Historique_Rdv.accdb");
connection.Open();
string command = "INSERT INTO RendezVous " +
"(IDAnimal, NumeroRdv, DateRdv, Prestation, Temps, ComplementInfo, Paye, IDProprietaire) " +
"VALUES(" + int.Parse(TB_idAnimalNewRdv.Text) + ", " + int.Parse(TB_numeroRdvNouveauRdv.Text) + ", '" + TB_dateNouveauRdv.Text + "', '" + TB_actionNouveauRdv.Text + "', '" + TB_tempsNouveauRdv.Text + "', '" + TB_complementInfoNouveauRdv.Text + "', " + int.Parse(TB_payeNouveauRdv.Text) + ", " + int.Parse(TB_idProprietaireNewRdv.Text) + " )";
OleDbCommand cmdd = new OleDbCommand(command, connection);
cmdd.ExecuteNonQuery();
connection.Close();