类似数组的结构

structure like array

我正在从我的数据库中选择 2 列 - PPIDNAME。我想存储相关的两个值。

那么假设现在我们有这个:

|PPID |NAME
|1    |Admin
|2    |Aleksa
|3    |Marija
|4    |Predrag
|5    |Bojana

现在在组合框中,我显示 Names,当有人按 Predrag 时,我想要他的 ppid (4) 以供进一步使用。

我尝试使用结构,但效果不佳。如果你有什么想法,请写信给我。请记住,这个示例有 5 行,但实际上我不知道有多少行,所以它不可能是静态的。

尝试使用 Dictionary 并将您的组合框绑定到词典。

例如(假设 PPID 是唯一的):

Dictionary<int, string> myDictionary = new Dictionary<int, string>
            {
                {1, "Admin"},
                {2, "Aleksa"},
                {3, "Marija"},
                {4, "Predrag"},
                {5, "Bojana"}
            };

写一个 class 让你数据库中的每个人都有自己的实例怎么样?

class YourClass

{ 
public integer PPID {get;set;}
public string Name {get;set;}
}

static void Main()
{
// Just an example...
// SQL command already executed, data readers declared and so on...

int i=0;

YourClass[] arr = new YourClass[];

while(yourDataReader.Read()){
  arr[i] = new YourClass();
  arr[i].PPID = yourDataReader.GetInt32(0);
  arr[i].Name = yourDataReader.GetString(1);
}