i have problems with a sql command in mysql. I have a asp.net applcation and use a mysql database as database. I want to built a class that can insert,update,delete and select the records in the database. I have problems with the update command. In phpmyadmin it works but in my class not :/
Here is my code
public void UpdateRecord(string title, string firstname, string lastname, string company,
string timefrom, string timeto)
{
connection = new MySqlConnection();
try
{
MySqlCommand command = connection.CreateCommand();
//for testing
string sql = "UPDATE 'tb_gast' SET FIRSTNAME='test' WHERE ID=270";
command.CommandText = sql;
connection.Open();
command.ExecuteNonQuery();
}
catch (Exception)
{
}
finally
{
connection.Close();
}
}
this command work in phpmyadmin
UPDATE `tb_gast`
SET
FIRSTNAME='uu',
LASTNAME='uu',
COMPANY='uu'
WHERE ID=270
You are using single quote around the tablename, instead of backticks.
The backtick could be typed using the key combination
ALT+096EDIT: Looking at your question more in deep.
Noticed that you declare a MySqlConnection and initialize it WITHOUT any connection strings.
If this is your real code no wonder that it doesn’t work
This is how your code should be
where GetConnectionString() should be some method that returns your connection string from some permanent storage like a configuration file