-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 に答える