private void Form1_Load(object sender, EventArgs e)
{
List<string> Tempstrs;
String strSQL = "SELECT ID FROM Words ";
Tempstrs = FindItems(strSQL);
for (int i = 0; i < Tempstrs.Count; i++)
{
PublicClass.MyWords[i].Number = Tempstrs[i];
}
strSQL = "SELECT English FROM Words ";
Tempstrs = FindItems(strSQL);
for (int i = 0; i < Tempstrs.Count; i++)
{
PublicClass.MyWords[i].English = Tempstrs[i];
}
strSQL = "SELECT Chinese FROM Words ";
Tempstrs = FindItems(strSQL);
for (int i = 0; i < Tempstrs.Count; i++)
{
PublicClass.MyWords[i].Chinese = Tempstrs[i];
}
strSQL = "SELECT Levels FROM Words ";
Tempstrs = FindItems(strSQL);
for (int i = 0; i < Tempstrs.Count; i++)
{
PublicClass.MyWords[i].Levels = Tempstrs[i];
}
int GroupNumber = Tempstrs.Count / 100 + 1;
PublicClass.GroupNumberCount = GroupNumber;
PublicClass.WordNumberCount = Tempstrs.Count;
ShowGroups();
}
private List<string> FindItems(string strSQL)//从数据库中查询各个选择项的内容
{
List<string> InputData = new List<string>();
string MySource = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|//Words.accdb";//ACCESS链接字符串
OleDbConnection myConnection = new OleDbConnection(MySource); //OleDb链接类的实例化
myConnection.Open();//打开数据库
OleDbCommand MyCommand = new OleDbCommand(strSQL, myConnection);//创建Command命令对象
OleDbDataReader dr = MyCommand.ExecuteReader();//创建DataReader对象,并调用ExecuteReader从数据源检索行
int ItemNumber = 0;
while (dr.Read())//启动阅读器的Read方法,返回行的每一列
{
ItemNumber++;
InputData.Add(dr[0].ToString());//..数据读取
}
dr.Close();//关闭阅读器
myConnection.Close();//关闭数据库
return InputData;
}