C# GetCountry查询中我的SQL语法出错

C# GetCountry查询中我的SQL语法出错,c#,mysql,visual-studio,syntax-error,C#,Mysql,Visual Studio,Syntax Error,我的代码中出现语法错误。线路适配器处出现错误。Filldt;在adapter.SelectCommand.CommandText=@SELECT c.*之后,选择来自用户的首字母缩写。。。。线错误显示,请检查与MySQL服务器版本对应的手册,以获取第1行“237 ORDER BY c.CountryName”附近使用的正确语法,但我不确定是什么导致了此错误 public static string GetCountry(int CountryID) { string Country =

我的代码中出现语法错误。线路适配器处出现错误。Filldt;在adapter.SelectCommand.CommandText=@SELECT c.*之后,选择来自用户的首字母缩写。。。。线错误显示,请检查与MySQL服务器版本对应的手册,以获取第1行“237 ORDER BY c.CountryName”附近使用的正确语法,但我不确定是什么导致了此错误

public static string GetCountry(int CountryID)
{
    string Country = "";

    string sql = "proc_GetCountries";

    DataTable dt = new DataTable();

    using (MySql.Data.MySqlClient.MySqlDataAdapter adapter = new MySql.Data.MySqlClient.MySqlDataAdapter(sql, DataUtils.ConnectionStrings["TAT"]))
    {
        adapter.SelectCommand.CommandType = CommandType.Text;
        adapter.SelectCommand.CommandText = @"SELECT * FROM countries WHERE ID = ?countryID ORDER BY CountryName";
        adapter.SelectCommand.Parameters.Add(new MySqlParameter("countryID", CountryID));
        adapter.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            Country = dt.Rows[0]["CountryName"].ToString();
        }
    }
    return Country;
}
public static DataSet GetCountry(int Company_ID, int ID)
{
    DataSet ds = new DataSet();

    string sql = "proc_GetCountry";

    DataTable dt = new DataTable(), dtRates = new DataTable(), dtDepots = new DataTable();

    using (MySql.Data.MySqlClient.MySqlDataAdapter adapter = new MySql.Data.MySqlClient.MySqlDataAdapter(sql, DataUtils.ConnectionStrings["TAT"]))
    {
        adapter.SelectCommand.CommandType = CommandType.Text;
        adapter.SelectCommand.CommandText = @"SELECT c.*,(Select Initials FROM users WHERE User_ID = c.CreatedByUser) AS CreatedBy, (SELECT Initials FROM users WHERE User_ID = c.ModifiedByUser) AS ModifiedBy " +
            "FROM countries c WHERE c.Company_ID = ?company_ID AND c.ID ?iD ORDER BY c.CountryName";
        adapter.SelectCommand.Parameters.Add(new MySqlParameter("company_ID", Company_ID));
        adapter.SelectCommand.Parameters.Add(new MySqlParameter("iD", ID));
        adapter.Fill(dt);
        ds.Tables.Add(dt);
    }
    //Rates
    using (MySql.Data.MySqlClient.MySqlDataAdapter adapter = new MySql.Data.MySqlClient.MySqlDataAdapter(sql, DataUtils.ConnectionStrings["TAT"]))
    {
        adapter.SelectCommand.CommandType = CommandType.Text;
        adapter.SelectCommand.CommandText = @"SELECT cc.* FROM country_rates cc WHERE cc.CountryID ?iD";
        adapter.SelectCommand.Parameters.Add(new MySqlParameter("iD", ID));
        adapter.Fill(dtRates);
        ds.Tables.Add(dtRates);
    }
    //Depots
    using (MySql.Data.MySqlClient.MySqlDataAdapter adapter = new MySql.Data.MySqlClient.MySqlDataAdapter(sql, DataUtils.ConnectionStrings["TAT"]))
    {
        adapter.SelectCommand.CommandType = CommandType.Text;
        adapter.SelectCommand.CommandText = @"SELECT cc.* FROM country_depot cc WHERE cc.CountryID = ?iD";
        adapter.SelectCommand.Parameters.Add(new MySqlParameter("iD", ID));
        adapter.Fill(dtDepots);
        ds.Tables.Add(dtDepots);
    }
    return ds;
}
试试这个,你缺少=在c.ID?ID:


c、 ID?ID missing=?顺便说一句,您应该首先在数据库管理器中尝试查询。有了它,你可以确定它在你的代码中也不会起作用
adapter.SelectCommand.CommandText = @"SELECT c.*,(Select Initials FROM users WHERE User_ID = c.CreatedByUser) AS CreatedBy, (SELECT Initials FROM users WHERE User_ID = c.ModifiedByUser) AS ModifiedBy " +
                   "FROM countries c WHERE c.Company_ID = ? company_ID AND c.ID = ? iD ORDER BY c.CountryName";