-2

我已经尝试了几个小时,但我无法弄清楚我们出了什么问题

var cmd = new SqlCommand();
cmd.Parameters.Clear();
cmd.Connection = mySqlConnection;
cmd.CommandType = CommandType.Text;
cmd.CommandText = 
    "select Calle.Id_Calle FROM" + 
      "TominPredial.Calle as Calle,"+
      "TominPredial.Colonia as Col," +
      "TominPredial.Poblacion as Pob" +
     "WHERE Calle.Nombre = @NombreCalle" +
            "and Col.Id_Colonia = @id_col and Pob.Id_Poblacion = @id_pob";
cmd.Parameters.Add("@NombreCalle", nombreCalle);
cmd.Parameters.Add("@id_col", id_col);
cmd.Parameters.Add("@id_pob", id_pob);
cmd.ExecuteScalar()

它在“Calle”附近显示不正确的语法

4

1 回答 1

10

行之间没有空格:

"select Calle.Id_Calle FROM" + 
  "TominPredial.Calle as Calle,"+
  "TominPredial.Colonia as Col," +
  "TominPredial.Poblacion as Pob" +
 "WHERE Calle.Nombre = @NombreCalle" +
        "and Col.Id_Colonia = @id_col and Pob.Id_Poblacion = @id_pob";

这将使查询... FROMTominpredial.calle ... pobWHERE ..产生语法错误。

您必须在行尾的关键字之间放置空格。像这样:

...
"select Calle.Id_Calle FROM" + 
" TominPredial.Calle as Calle,"+
" TominPredial.Colonia as Col," +
" TominPredial.Poblacion as Pob" +
" WHERE Calle.Nombre = @NombreCalle" +
"   and Col.Id_Colonia = @id_col and Pob.Id_Poblacion = @id_pob"; 
/\
put a Spaces here
于 2012-12-02T08:05:46.457 回答