-3

I have a code part with List<object> like that:

List<object> Result= new List<object>();
Some sql connection code...

SqlCommand com = new SqlCommand(@" Select TOP(10) a,b,c from table

Some sql connection code...

 while (rd.Read())
        {
           Result.Add(new
            {                  
               a=rd[0],
               b=rd[1],              
               c=rd[2]    
            });  
        }
        rd.Close();
        con.Close();

I want to add some statement for Result value. For example

if(a == "") 
a=5;

and i use List<object> in javascript part

var listCategory = $find("ace2").get_completionList();

          var count2 = listCategory .childNodes.length;
          for (j =0; j < count2; j++) {                
              var item2 = listCategory .childNodes[j]._value;
              var a= item2.a;
              var b= item2.b;
              var c= item2.c;
          }

and i use this value in html.

How to add some statement for List<object>() value ?


How to set the UIDatePicker in 24hours in ios5?

Please help me. I have a bug in iOS5 thats set the locale into 12-hours mode in iOS6 is working fine.

this are my code.

NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"NL"];

[self.timePickerView setLocale:locale];
[self.timePickerView setTimeZone:[NSTimeZone defaultTimeZone]];
[self.timePickerView setDate:self.date animated:NO];

what is wrong with my code? I want to have a default 24hours on my UIDatePicker. please help me thanks!

4

2 回答 2

1

不知道您要返回多少列?如果您确实知道创建一个持有者类,否则您必须自己处理铸造并且不易维护。

List<KnownType> Result= new List<KnownType>();
a=rd[0];
b=rd[1],
c=rd[2]  
if(a=="" or string.IsNullOrEmpty(a) or YourCondition)
{
change what ever values you want
}
Result.Add(new KnownType
            {                  
               a,b,c
            });
于 2013-06-24T07:10:44.570 回答
0

如果我理解正确,您想在将运行时类型添加到列表之前对其进行条件初始化。

所以你可以创建一个函数:

public object GetObject(SqlDataReader rd) {


    var aVal = rd[0]; 
    if(string.IsNullOrEmpty(aVal)) 
        aVal = "5"; //STRING, in your case it's a NUMBER

    return new
           {                  
              a=aVal,
              b=rd[1],              
              c=rd[2]    
           });  
}

并在添加后使用它:

while (rd.Read())
{
    ....
    Result.Add(GetObject(rd)); 
    .....
}

如果这不是您要的,请澄清。

于 2013-06-24T06:37:41.420 回答