在字段列表上名为''的字段不明确

时间:2013-04-01 20:10:49

标签: asp.net mysql

string sql = @"
 SELECT 
       sit.descricao       AS situacao, 
       pri.prioridade      AS prioridade, 
       usr.nome            AS responsavel, 
       ch.previsao_termino AS previsao, 
       ch.descricao        AS descricao, 
       clb.clube, 
       proj.descricao      AS projeto, 
       func.descricao      AS funcionalidade 
FROM   
       chamados AS ch 
LEFT JOIN 
       prioridades AS pri 
ON 
       ch.prioridade = pri.id 
INNER JOIN 
       situacoes AS sit 
ON 
       ch.situacao = sit.id 
LEFT JOIN 
       usuarios AS usr 
ON 
       ch.responsavel = usr.id 
INNER JOIN 
       clubes AS clb 
ON 
       ch.clube = clb.id 
INNER JOIN 
       projetos AS proj 
ON 
       ch.projeto = proj.id 
INNER JOIN 
       funcionalidades AS func 
ON 
      ch.funcionalidade = func.id 
WHERE  
      ch.id = @id";


MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32)).Value = _ch.ID;
DataSet retorno = _dal.Consultar(cmd);
return retorno;

当它返回时它不是空的,但是当我这样做时:

GridView1.DataSource(retorno);
GridView1.DataBind(); //Here Fires the error.

它会触发标题上的错误。我在这里阅读了很多其他主题,但我看不出它的含糊之处。是我的疑问?或者其他的东西......它正在工作然后我再次进行了重新校对,错误被解雇了......

错误:

a field named 'prioridade' on field list is ambiguous

1 个答案:

答案 0 :(得分:0)

chamadosprioridades表都有一个名为prioridade的字段。因此,您无法在SELECT语句中将该字段名称用作别名。

尝试pri.prioridade AS prioridad或类似的东西。