Hi
I have a problem with inserting strings.
I'm using MySql with a ODBC connection.
eg:
code = "mycode";
desc = "It's not working";
string sql = "";
sql = "insert into pasCustomerCodes(code,description) values('" + code + "','" + desc + "')";
OdbcCom = new System.Data.Odbc.OdbcCommand(sql, OdbcCon);
OdbcCom.ExecuteNonQuery();
---------
This gives an erro because of the ' character in the desc string.
Is there anything I can use to fix this?
Thanks
Loading

Gaurish Kumar108 reputationPosted Jan 18, 2010, 11:41 PM EST
Change this line of your code. and it works.
desc = "It''s not working";
paul daniel189 reputationPosted Jan 19, 2010, 3:20 AM EST
Sp code
CREATE DEFINER=`stefan`@`%` PROCEDURE `City_Insert`(in p_in_city varchar(50), in p_in_country_id int) BEGIN insert into city (city,country_id) values( p_in_city, p_in_country_id); select LAST_INSERT_ID(); END$$ C# code: public long InsertMySQL_GetLast_SP(string city, int country_id) { MySql.Data.MySqlClient.MySqlConnection oConn = new MySql.Data.MySqlClient.MySqlConnection("Database=sakila;Data Source=192.168.10.4;User id=stefan;Password=pekka"); oConn.Open(); MySql.Data.MySqlClient.MySqlCommand command = new MySql.Data.MySqlClient.MySqlCommand("City_Insert", oConn); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("?p_in_city", MySql.Data.MySqlClient.MySqlDbType.VarChar, 50)); command.Parameters.Add(new MySql.Data.MySqlClient.MySqlParameter("?p_in_country_id", MySql.Data.MySqlClient.MySqlDbType.Int64)); command.Parameters[0].Value = city; command.Parameters[1].Value = country_id; //command.ExecuteNonQuery(); long lNewId = (long)command.ExecuteScalar(); oConn.Close(); return lNewId; }Felipe Marks72 reputationPosted Jan 21, 2010, 10:35 PM EST
Gaurish your idea is the one I'm going with. It's simple and it works. Thanks
Paul, I think you have the best answer, I don't have the MySql Library included so I didn't want to go that route.