我正在尝试使用此结构将从 DataTable 中获得的几行添加到我的列表中:
protected struct roleProperties
{
public string roleName { get; set; }
public string[] functionTitle { get; set; }
}
如您所见,我想要方法字符串中的更多Title
字符串
我一直在尝试这样做:
public void getRoleFuncs(int roleId)
{
List<roleProperties> roles = new List<roleProperties>();
int i = 1;
SqlParameter ro_id = new SqlParameter("@ro_id", roleId);
string q = "SELECT ro_name, fu_title FROM roles INNER JOIN rolefunctions ON roles.ro_id = rolefunctions.fk_role_id INNER JOIN functions ON rolefunctions.fk_func_id = functions.fu_id WHERE ro_id = @ro_id";
SqlDataReader r = gm.returnReader(q, ro_id);
while (r.Read())
{
roleProperties item = new roleProperties();
item.roleName = r["ro_name"].ToString();
foreach (IDataRecord str in r)
{
item.functionTitle[i] = r["fu_title"].ToString();
i++;
}
roles.Add(item);
}
}
但我在这一行得到一个空引用:
item.functionTitle[i] = r["fu_title"].ToString();
谁能看到我做错了什么?