2012-06-17 24 views
1

我想要得到的e.result它抽數據到我listbox..I前要檢查的e.result是否爲空或有值.. 我的編碼是這樣如何檢查e.result?

public Page1(string s) 
{ 
    InitializeComponent(); 
    Service1Client proxy = new Service1Client(); 
    proxy.FindEmployeeCompleted += new EventHandler<FindEmployeeCompletedEventArgs>(proxy_FindEmployeeCompleted); 
    proxy.FindEmployeeAsync(s); 
} 
void proxy_FindEmployeeCompleted(object sender, FindEmployeeCompletedEventArgs e) 
{ 
    if(e.Result!=null) 
    { 
     listBox1.ItemsSource = e.Result; 
    } 
    else 
    { 
    MessageBox.Show("Invalid username or password."); 
    } 
} 

但我執行後我的編碼,消息框沒有顯示出來... 它是我錯過任何代碼?

回答

1
static void proxy_FindEmployeeCompleted(object sender, FindEmployeeCompletedEventArgs e) 
{ 
    if (e.Error != null) 
    { 
     MessageBox.Show(e.Error.Message); 
    } 
    else if (e.Result != null) 
    { 
     // you can check results here. 
     if (e.Result.Any()) 
     { 
      listBox1.ItemsSource = e.Result; 
     }else 
     { 
      // empty result, show message or whatever 
     } 
    } 
    else 
    { 
     MessageBox.Show("Invalid username or password."); 
    } 
}