我已经尝试了几个小时,但我无法弄清楚我们的错误
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”
附近的语法不正确答案 0 :(得分: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