私はアクセス データベースを持っています。フィールドの 1 つは、管理者がジョブを選択できるようにするチェック ボックスのリストです。スパム防止メカニズムのおかげで画像を投稿できませんでした。このフィールドを次のように記述させてください。
ジョブ
(チェックボックス) ガーデニング
(チェックボックス) カーペットクリーニング
(チェックボックス) トイレ掃除
(チェックボックス) 窓掃除
管理者は、気分に応じて、複数のジョブを選択するか、ジョブをまったく選択できないようにする必要があります。
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;
}