我有一种方法可以查询数据库以获取 GUID 列表,然后将它们添加到数组中。我希望我的方法从数组中返回一个特定的 GUID(基于组合框选择索引)。以下尝试产生标题中的错误。
public string PopulateDivisions(string qs, string cs)
{
using (SqlConnection connection = new SqlConnection(cs))
{
connection.Open();
SqlCommand command = new SqlCommand(qs, connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
int ordinal = reader.GetOrdinal("Name");
Div_Selecter.Items.Add(reader.GetString(ordinal));
//Data_Result.Items.Add(reader.GetString(ordinal));
}
Div_Selecter.SelectedIndex = 1;
while (reader.Read())
{
int ordinal2 = reader.GetOrdinal("Id");
for (int i=0; i<=ordinal2; i++)
{
string[] divisionIDs = new string[i];
divisionIDs[i] = reader.GetString(ordinal2);
}
}
string selectedDivisionID = divisionIDs[Div_Selecter.SelectedIndex];
return selectedDivisionID;
}
}