Not sure this question has been asked before though. If it were, my apologies.
I need to remove an apostrophe character from a string.
The reason for this has to be done because it's triggering an error in the SQL query for client's name which I fetch from the local database.
The error indicates near the 'apostrophe s'.
When I remove that data field from the local database error ain't appear.
I came up with a solution for removing the apostrophe character from the client name.
I tried to use Remove() function but it only works for integers. (string to int conversion error).
My code is as follows:
while (rdr.Read())
{
int promised_date = (int)(rdr.GetValue(0));
string strClientName = (rdr.GetValue(1).ToString());
string strClientReference = (rdr.GetValue(2).ToString());
string strJobCategory = (rdr.GetValue(3).ToString());
string datCommisioned = (rdr.GetValue(4).ToString());
string datPromisedDelivery = (rdr.GetValue(5).ToString());
if (this.OpenConnection() == true)
{
string querynew = "INSERT INTO jobs_table (nJobNumber,strClientName,strClientReference,strJobCategory,datCommisioned,datPromisedDelivery) VALUES ("+promised_date+",'"+strClientName+"','"+strClientReference+"','"+strJobCategory+"','"+datCommisioned+"','"+datPromisedDelivery+"' )";//yeyyy why only few?
MySqlCommand cmd = new MySqlCommand(querynew, connection);
cmd.ExecuteNonQuery();
this.CloseConnection();
}
}
Does anyone have an idea how to remove the apostrophe from strClientName when reading the data?