2015-04-03 75 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查询查询数据表并添加到列表中。谢谢大家的全力帮助