我已经在我的 C# 程序中将数据库表读入 DataTable 中,但是在将包含位值的列分配给布尔值时遇到了一些问题。
到目前为止,这是我的代码:
// Load and Sort Users DataTable
DataTable datatableUsers = UserMethods.GetUsers().Tables["Users"];
datatableUsers.DefaultView.Sort = "Name";
// Filter Based on Search Box
datatableUsers.DefaultView.RowFilter = "Name LIKE '%" + user + "%' OR Username LIKE '%" + user + "%'"; ;
DataView dataviewUsers = datatableUsers.DefaultView;
// Loop Through Rows and Add UsersGrid to FlowLayoutPael
foreach (DataRowView datarowviewUsers in dataviewUsers)
{
var UsersGrid = new UsersGrid
{
ID = (int)datarowviewUsers["ID"],
Username = datarowviewUsers["Username"].ToString(),
User = datarowviewUsers["Name"].ToString(),
Admin = datarowviewUsers["Administrator"].ToString(),
};
flowlayoutpanelUsers.Controls.Add(UsersGrid);
UsersGrid.WasClicked += UsersGrid_WasClicked;
}
目前,我正在转换 Admin ToString 并在“True”上进行匹配,但这变得非常混乱,我更愿意将 Admin 设置为布尔类型。我需要做什么?