1. This is a part of my code. Help please. Rrror CS1503: Argument `#1' cannot convert `string' expression to type `int'. But how? I should to compare row with player name.
    Code:
    string query;
                query = string.Format("SELECT `steamid`, `user` FROM `{0}` WHERE `clan` = '{1}' LIMIT 1", dbConnection["Table"], ClanName);
                _mySql.Query(Sql.Builder.Append(query), _mySqlConnection, (List<Dictionary<string, object>> row) =>
                {
                    var playerslist = new List<string> {string.Empty};
                    foreach (var players in GameManager.Instance.GetSessions())
                    {
                        object user = row["user"];
                        var tplayer = players.Value;
                        var compare = String.Equals(tplayer.Name, user);
                        if (!tplayer.IsLoaded) continue;
                        if (compare == false) continue;
    [DOUBLEPOST=1454616634,1454599677][/DOUBLEPOST]Please help. I need this urgently.
     
  2. Wulf

    Wulf Community Admin

    You can't compare a string with an int, you'll need to either case or use ToString() where your int is. The issue is with your String.Equals.
     
  3. I don't understand. Can you fix my code? I will be very glad ;) Please
     
  4. I don't know C#, but:
    Code:
    var compare = String.Equals(tplayer.Name, user.ToString());
     
  5. I tryied. Don't work.
     
  6. At what line is the error?
     
  7. object user = row["user"];
    I tryied string, int, ToString(). Nothing doesn't work
     
  8. Of what type is "row"?
     
  9. I don't know. row is from MYSQL. What type is row default?
    [DOUBLEPOST=1454756762][/DOUBLEPOST]
    _mySql.Query(Sql.Builder.Append(query), _mySqlConnection, (List<Dictionary<string, object>> row)
    Maybe here is saying? I don't know so good.
    [DOUBLEPOST=1454834581,1454756718][/DOUBLEPOST]UP
    [DOUBLEPOST=1454943415][/DOUBLEPOST]Anybody will help?
     
  10. object user = row["user"];
    to
    var user = row["user"];

    It is hard to help if we do not have more info, like what data does user have? Is it a username?
     
  11. object to var should not make a big difference here.
    [DOUBLEPOST=1455176750][/DOUBLEPOST]
    Try running
    PrintWarning(row.GetType().ToString());
     
  12. @LaserHydra I suggested the var because tostring doesn't work on an object, or am I mistaken?
    [DOUBLEPOST=1455177094][/DOUBLEPOST]and if the error really is on that row, it's omplaining that it can't make a string into an object. eother way more info is needed to help the guy
     
  13. As far as I know everything can be in an object. I think the key should be an int. Thats why I want to know, what type 'row' is of.
     
    Last edited by a moderator: Feb 11, 2016
  14. I don't know so good, but i find smth on MySQL Extension page:
    • Query(Sql sql, Connection db, Action<List<Dictionary<string, object>>> callback) where db is the variable you create with OpenDb() and sql is created by NewSql
    Maybe this will help.
     
  15. Nvm me. Found your issue. Your 'row' variable is a List<Dictionary<string, object>> you can not use row["user"] that could only be done on a dictionary. You need to use an int there. As I don't know your environment and what exactly the list contains, i can not help you further than telling you that its a list. For example row[0] would work if the list is not empty.
     
  16. So. It's full code:
    Code:
    void ClanMembers(object ClanName, PlayerSession player, ulong steamID)
            {
                string query;
                query = string.Format("SELECT `steamid`, `user` FROM `{0}` WHERE `clan` = '{1}' LIMIT 1", dbConnection["Table"], ClanName);
                _mySql.Query(Sql.Builder.Append(query), _mySqlConnection, (List<Dictionary<string, object>> row) =>
                {
                    var playerslist = new List<string> {string.Empty};
                    foreach (var players in GameManager.Instance.GetSessions())
                    {
                        object user = row["user"];
                        var target = players.Value;
                        var compare = String.Equals(target.Name, user);
                        if (!target.IsLoaded) continue;
                        if (compare == false) continue;                    if (playerslist[playerslist.Count - 1].Length + target.Name.Length > 50)
                            playerslist.Add(string.Empty);
                        if (playerslist[playerslist.Count - 1] != string.Empty)
                            playerslist[playerslist.Count - 1] += ", ";
                       
                        playerslist[playerslist.Count - 1] += $"<color=green>{target.Name}</color>";
                    }
                    if (playerslist[playerslist.Count - 1] != string.Empty)
                    foreach(var msg in playerslist) hurt.SendChatMessage(player, msg);
                    else hurt.SendChatMessage(player, "Offline");
                });
            }
     
  17. from what hydra said, you will have to loop the users if you want to find them all. Since a clan can contain multiple users.

    example:
    foreach (var user in row)
    {

    }