我有一个访问数据库,其中一个字段是复选框列表,允许我们的管理员选择作业。由于该垃圾邮件预防机制,我无法发布图片,请允许我将此字段描述如下:
工作
(复选框)园艺
(复选框)地毯清洁
(勾选)厕所清洁
(复选框)窗户清洁
管理员应该能够选择多个工作或根本没有工作,这取决于他的心情。
我必须使用 C# 创建一个 UI,那么如何以编程方式从 C# 访问此字段,修改后如何将其放回数据库?
编辑:此字段在 Access 2010 中如下所示:http: //i48.tinypic.com/9k1204.jpg
编辑:
下面是我用来从数据库中获取行的代码
public List<Contractor> GetContractors()
{
//connect to local database file and read everything from contractor table
OleDbConnection myConnection = new OleDbConnection(/*local database file*/);
myConnection.Open();
string sql = "SELECT * FROM Contractors";
OleDbCommand myCommand = new OleDbCommand(sql, myConnection);
OleDbDataReader myReader = myCommand.ExecuteReader();
//contractor lists that to be returned
List<Contractor> contractors = new List<Contractor>();
//raw data from database
ArrayList records = new ArrayList();
while (myReader.Read())
{
Hashtable row = new Hashtable();
for (int i = 0; i < myReader.FieldCount; i++)
{
row.Add(myReader.GetName(i), myReader[i]);
}
records.Add(row);
}
//fetch rows, and construct a temp Contractor based on rows
for (int i = 0; i < records.Count; i++)
{
Contractor tempContractor = new Contractor();
Hashtable row = (Hashtable)records[i];
tempContractor.ID = Convert.ToInt32(row["ID"]);
tempContractor.FamilyName = Convert.ToString(row["FamilyName"]);
tempContractor.GivenNames = Convert.ToString(row["GivenNames"]);
tempContractor.Address = Convert.ToString(row["Address"]);
tempContractor.Phone = Convert.ToString(row["Phone"]);
tempContractor.Mobile = Convert.ToString(row["Mobile"]);
tempContractor.Email = Convert.ToString(row["Email"]);
tempContractor.DateOfBirth = Convert.ToDateTime(row["DOB"]);
tempContractor.Status = this.getTableItem(contractorStatus, Convert.ToInt32(row["Status"]));
tempContractor.Comments = Convert.ToString(row["Comments"]);
//+++++++++++++++++++++++++++++++++++
tempContractor.Jobs = Convert.ToString(row["Jobs"]); //<------ this is how I try to fetch the dropdown list field in database, it doesn't work
//++++++++++++++++++++++++++++++++++++
contractors.Add(tempContractor);
}
return contractors;
}