我'得到以下錯誤:我不能在c#中解決這個錯誤?
You have an error in your
SQL
syntax; check the manual that corresponds to yourMySQL
server version for the right syntax to use near "temp" at line 1.
下面的代碼:
public void DeleteColumn(string columnName)
{
try
{
query.CommandText = "alter table publisher drop @col ";
query.Prepare();
query.Parameters.AddWithValue("@col", columnName);
query.ExecuteNonQuery();
Console.WriteLine("column deleted successfully");
transaction.Commit();
Console.WriteLine("successfully committed to database");
}
catch (MySqlException ex)
{
Console.WriteLine(ex.Message);
}
}
我這是在傳遞DeleteColumn值:
DeleteColumn("temp");
沒有連接問題,我已經定義了每個需要的值
你有沒有調試代碼,如果是,請告訴我哪行代碼拋出異常 – Pawan
是的。 query.ExecuteNonQuery();拋出異常 – Ankit0047
query.CommandText =「alter table publisher DROP COLUMN @col」;將解決。改變這一行 – Pawan