, если вы хотите отфильтровать данные из DataTable, я бы предложил использовать DataView
DataView dv = new DataView();
dv = new DataView(parameterDs.Tables[0], "ParameterName = '@" + parameter.Key + "'",string.Empty, DataViewRowState.CurrentRows);
, вы также можете использовать сортировку в DataView
dv.Sort = "Name";
, а затем просто использовать
grid.DataSource = dv;
Другим способом использования DataView является назначение ему запроса:
DataTable contacts = dataSet.Tables["Contact"];
EnumerableRowCollection query = from contact in contacts.AsEnumerable()
where contact.Field("LastName").StartsWith("S")
orderby contact.Field("LastName"), contact.Field("FirstName")
select contact;
DataView view = query.AsDataView();
bindingSource1.DataSource = view;
dataGridView1.AutoResizeColumns();
или с помощью свойства DataView 'RowFilter':
DataTable contacts = dataSet.Tables["Contact"];
DataView view = contacts.AsDataView();
view.RowFilter = "LastName='Zhu'";
bindingSource1.DataSource = view;
dataGridView1.AutoResizeColumns();
, и всякий раз, когда вы хотите очистить свой фильтр, просто напишите:
view.RowFilter = null; //or String.Empty
private async authenticate(oldUser: User) {
try {
await this.authService.auth(this.oldUser).toPromise();
return;
} catch (reject) {
return;
}
}
Вы можете сделать так, чтобы .then
и .catch
возвращали что-то значимое, что отличает их, и затем проверяете этот отличительный фактор. Например:
const result = await this.authService.auth(this.oldUser).then((authorizedUser) => {
// do stuff with authorizedUser
return authorizedUser;
}).catch((err) => {
// handle errors, if needed
return { err };
});
if (result.err) {
// there was en error, return early:
return;
}
// rest of the code that depends on the first request being successful goes here
await this.authService.auth(this.newUser).then(...)
Обратите внимание, что если вы используете await
, может иметь смысл использовать try/catch
, а не .then
с и await
] s:
try {
const authorizedUser = await this.authService.auth(this.oldUser)
// do stuff with authorizedUser
// rest of the code that depends on the first request being successful goes here
const newAuthorizedUser = await this.authService.auth(this.newUser);
// do stuff with newAuthorizedUser
} catch(err) {
// handle errors, if needed
return;
}