我忙于c#windows窗体中的任务程序。我编写了一个应该完成这项工作的代码,但不知怎的。在第一个foreach语句中,他停止执行该方法。
这是我的代码:
int userid = 1;
MySqlCommand mscSelectId = new MySqlCommand("SELECT * FROM pakket WHERE gebruikersid=@userid", _msConnection);
mscSelectId.Parameters.AddWithValue("@userid", userid);
MySqlDataReader msSelectid = mscSelectId.ExecuteReader();
DataTable dtSelectId = new DataTable();
dtSelectId.Load(msSelectid);
string[] saAllid = new string[dtSelectId.Rows.Count + 1];
int a = 0;
foreach (DataRow row in dtSelectId.Rows)
{
saAllid[a] = (string)row["groepsid"];
a++;
}
int b = 0;
int c = 0;
foreach (string item in saAllid)
{
MySqlCommand mscSelectGroep = new MySqlCommand("SELECT * FROM groep WHERE id=@groepsid", _msConnection);
mscSelectGroep.Parameters.AddWithValue("@groepsid", saAllid[b]);
MySqlDataReader msSelectedGroep = mscSelectGroep.ExecuteReader();
DataTable dtSelectGroep = new DataTable();
dtSelectGroep.Load(msSelectedGroep);
b++;
saGroepNaam = new string[dtSelectGroep.Rows.Count + 1];
foreach (DataRow row in dtSelectGroep.Rows)
{
saGroepNaam[c] = (string)row["groepsnaam"];
c++;
}
}
int d = 0;
int mtop = 10;
int mleft = 15;
int count = 1;
List<Label> _lListGroep = new List<Label>();
foreach (string item in saGroepNaam)
{
Label temp = new Label();
temp.Name = "lb" + d;
temp.Text = saGroepNaam[d];
temp.Width = 285;
temp.Height = 20;
temp.Left = 5;
temp.Top = mtop;
temp.BorderStyle = BorderStyle.Fixed3D;
mleft += 5;
if (count == 1)
{
mtop += 25;
mleft = 5;
count = 0;
}
count++;
d++;
_lListGroep.Add(temp);
}
return _lListGroep.ToArray();
感谢您的帮助