2015-04-03 60 views
0

我有一個拉動的值的表,如果有該列中的錯誤信息,我需要給一個硬編碼的消息說:「發現錯誤」追加到在C#中的列表

// Property 
Public partial Class section: IXmlserializable 
public List<string> ErrorMessage {get, set} 

if(ErrorMessage != null && ErrorMessage.Count > 0) 
    Writer.WriteElement("Notifications") 

Writer.WriteEndElement(); 

// I call this in my Body of the Page 
Datatable dt = this.GetErrorMessage(rountingcode, BookKey,userobject) 

if(dt != null dt.Rows.Count > 0) 
{ 
    Book.ErrorMessage.add(dt.Rows[0]["ErrorColumn"].ToString()); 
} 

// Idea is to add from the Book to its SECTION property ErrorMessage 
if(Book.ErrorMessage!= null && Book.ErrorMessage.Count>0) 
// INITIALIZE 

sec.ErrorMessage = new List<string>(); 
// IF the Book does contain any Error message that we pulled from the table 
// Display HARD coded message 
sec.ErrorMessage.Add("Hey Buddy you have a error in the BODY ") 
} 

現在如果我有一些其他錯誤,因爲在我的Header Book.ErrorMessage中,使用相同的PROPERTY ErrorMessage(其中包含STRING(「嘿,好友,您在頭文件中有錯誤」))的Header Book.ErrorMessage從其他一些dataTable中爲HEADER錯誤所以說到

if(dt != null dt.Rows.Count > 0) // It want go inside 

if(Book.ErrorMessage!= null && Book.ErrorMessage.Count>0) 
// Will go here 
// As it is using the same Property ErrorMessage for to get the HEADER 
//Error. 

有沒有辦法將其追加爲我們能夠同時顯示的ErrorMessage截至目前它總是覆蓋。

<Notification> 
Hey Buddy you have a error in the BODY 
Hey Buddy you have a error in the HEADER</Notification> 
+1

目前還不清楚你想要輸出什麼。你能用一個具體的例子來澄清嗎?另外,請檢查您的代碼。例如,你有'if(dt!= null dt.Rows.Count> 0)'。我想你在這兩個地方都缺少'&&'。並且縮進你的代碼不會有什麼壞處。 – 2015-04-03 04:19:41

+0

是的你是對的,但你有想法..它想要進入該循環,因爲我的Datatable沒有錯誤。 – user3920526 2015-04-03 13:14:26

回答

0

我是通過拉取一個包含錯誤列表的列來進行SQL查詢的。如果列中有1行爲錯誤,它應該使用數據表檢索值。我使用linq查詢查詢數據表並添加到列表中。謝謝大家的全力幫助