My function
public Permission[] GetPermissionsForGroupID(string groupID)
{
MySqlCommand command = new MySqlCommand();
command.Connection = connection;
command.CommandText = "SELECT `permissions`.`permissionName`, `groups_permissions`.`permissionValue`
FROM `db`.`groups_permissions`, `db`.`permissions`
WHERE `permissions`.`permissionID` = `groups_permissions`.`permissionID`
AND `groups_permissions`.`groupID` = '" + groupID + "'";
MySqlDataReader reader = command.ExecuteReader();
List<Permission> permissions = new List<Permission>();
while (reader.Read())
{
permissions.Add(new Permission((string)reader[0], (int)reader[1]));
}
reader.Close();
return permissions.ToArray();
}
throws an System.InvalidCastException at
permissions.Add(new Permission((string)reader[0], (int)reader[1]));
I narrowed it down to (string)reader[0] where a varchar should be casted into a string.
reader[0] = permissions.permissionName = varchar
What could be the problem?
EDIT:
The value of reader[0] is a string "kick_user_power" and the value of reader[1] is an integer "75".
EDIT 2:
The constructor of Permission
public Permission(string permissionName, int permissionPower)
{
PermissionName = permissionName;
PermissionPower = permissionPower;
}
And, for better visualization, the values of reader[0] and reader[1]:
