2014-02-17 118 views
1

所以我有一個程序在C#訪問從第三方程序的舊的Firebird 1.5數據庫。其中一個我有會爲任何一個報價或ID的項目獲取數據的方法:SQL命令不返回特定記錄

public static List<object> GetFollowUpData(int id, TipoFollowUp tipo) 
    { 
     var res = new List<object>(); 
     string q = tipo == TipoFollowUp.Orcamento 
      ? "SELECT ('Q-' || c.CLIENT_CODE || q.CQUO_FNUMB) as Codigo, q.CQUO_NAME as Nome, q.CQUO_SENT as Data, q.CQUO_TOTAL as Total, c.CLIENT_NAME as Empresa, m.CCON_NAME as Contacto, ((CASE WHEN m.CCON_PHONE1 IS null then '' else m.CCON_PHONE1 end) || '/' || (CASE WHEN m.CCON_PHONE2 IS null then '' else m.CCON_PHONE2 end) || '/' || (CASE WHEN m.CCON_PHONE3 IS null then '' else m.CCON_PHONE3 end) || '/' || (CASE WHEN m.CCON_PHONE4 IS null then '' else m.CCON_PHONE4 end) || '/' || (CASE WHEN c.CLIENT_PHONE1 IS null then '' else c.CLIENT_PHONE1 end) || '/' || (CASE WHEN c.CLIENT_PHONE2 IS null then '' else c.CLIENT_PHONE2 end) || '/' || (CASE WHEN c.CLIENT_PHONE3 IS null then '' else c.CLIENT_PHONE3 end) || '/' || (CASE WHEN c.CLIENT_PHONE4 IS null then '' else c.CLIENT_PHONE4 end)) as Telefones FROM CMULTIQUOTES q, CLIENTS c, CCONTACTS m WHERE q.ID = @id AND c.CLIENT_ID = q.CLIENT_ID AND q.CLIENT_PM = m.CCON_ID" 
      : "SELECT q.PROJ_CODE as Codigo, q.PROJ_NAME as Nome, q.PROJ_COMPLETED as Data, (select sum(j.CJOB_TOTAL) from CJOBS j where j.PROJ_ID = @id) as Total, c.CLIENT_NAME as Empresa, m.CCON_NAME as Contacto, ((CASE WHEN m.CCON_PHONE1 IS null then '' else m.CCON_PHONE1 end) || '/' || (CASE WHEN m.CCON_PHONE2 IS null then '' else m.CCON_PHONE2 end) || '/' || (CASE WHEN m.CCON_PHONE3 IS null then '' else m.CCON_PHONE3 end) || '/' || (CASE WHEN m.CCON_PHONE4 IS null then '' else m.CCON_PHONE4 end) || '/' || (CASE WHEN c.CLIENT_PHONE1 IS null then '' else c.CLIENT_PHONE1 end) || '/' || (CASE WHEN c.CLIENT_PHONE2 IS null then '' else c.CLIENT_PHONE2 end) || '/' || (CASE WHEN c.CLIENT_PHONE3 IS null then '' else c.CLIENT_PHONE3 end) || '/' || (CASE WHEN c.CLIENT_PHONE4 IS null then '' else c.CLIENT_PHONE4 end)) as Telefones FROM PROJECTS q, CLIENTS c, CCONTACTS m WHERE q.PROJ_ID = @id AND c.CLIENT_ID = q.CLIENT_ID AND q.CLIENT_PM = m.CCON_ID"; 
     using (var cmd = new FbCommand(q) {CommandType = CommandType.StoredProcedure}) 
     using (cmd.Connection = new FbConnection(ConnectionString)) 
     { 
      cmd.Connection.Open(); 
      cmd.Parameters.Add("@id", id); 
      using (FbDataReader reader = cmd.ExecuteReader()) 
      { 
       while (reader.Read()) 
       { 
        res.Add(id); // ID 
        res.Add(reader[0]); // Código 
        res.Add(reader[1]); // Nome 
        res.Add(reader[2]); // Data 
        res.Add(reader[3]); // Total 
        res.Add(reader[4]); // Empresa 
        res.Add(reader[5]); // Contacto 
        res.Add(reader[6]); // Telefones 
        res.Add(tipo); // Tipo 
       } 
       reader.Close(); 
      } 
      cmd.Connection.Close(); 
     } 
     return res; 
    } 

這工作的大部分時間(約在有一些葡萄牙語的話對不起) - 但是對於一個特定的項目它不返回任何數據(項目ID 8771)

我已經複製粘貼第二個查詢到FlameRobin,將它連接到數據庫,並用8771替換查詢中的@id,然後flameRobin返回我想要的數據。

因此,如果FlameRobin可以使用我的查詢來獲取數據,爲什麼我的程序不能得到它呢? 在我上面的方法中,Reader.Read() imediatly返回false,並且我沒有從該項目的數據庫中獲取數據。其他項目和報價到目前爲止沒有問題返回數據,據我所知

任何人有什麼想法嗎?

+0

無法讀取記錄的數據是什麼?是否有任何奇怪的字符(嵌入換行符,空值或其他奇怪字符),任何列爲空(但不在其他記錄中)? –

+0

@KlasLindbäck由於FlameRobin非返回的數據爲空或空。我無法準確地發佈數據本身,因爲它包含來自客戶端的個人數據,但沒有新行或空位出現 - 不確定您的意思是哪裏有奇怪的字符 – 537mfb

+0

我看到您有兩個不同的select語句。你有沒有在FlameRobin中嘗試過? –

回答

0

對不起大家 剛剛花了半天的時間,終於弄清楚我在開發/測試數據庫副本中(在VS下)並連接到FlameRobin的生產副本。

缺乏的TW數據庫之間的同步,造成這個

在生產複製中存在問題的項目 - 因此FlameRobin是顯示它 - 但不是在程序使用的開發/測試副本

對不起