08-29-2012, 01:53 AM
an other way to get to get stuff out the datatabel
public static string host, password, user;
public static string database_db;
.............................
public static List<CharacterContainer> Get_CharacterList(int UserID)
{
List<CharacterContainer> CharacterList = new List<CharacterContainer>();
try
{
MySqlConnection mysqlCon = new MySqlConnection(strProvider_db);
mysqlCon.Open();
MySqlCommand Command = new MySqlCommand("SELECT * FROM t_characters WHERE a_user_index = " + UserID + ";", mysqlCon);
Command.ExecuteNonQuery();
MySqlDataReader Reader = Command.ExecuteReader();
while (Reader.Read())
{
CharacterContainer temp = new CharacterContainer();
temp.a_index = Convert.ToInt32(Reader["a_index"]);
temp.a_user_index = Convert.ToInt32(Reader["a_user_index"]);
temp.a_name = (string)Reader["a_name"];
temp.a_nick = (string)Reader["a_nick"];
temp.a_enable = Convert.ToInt32(Reader["a_enable"]);
CharacterList.Add(temp);
}
mysqlCon.Close();
}
catch (Exception ex)
{
LogScreen.Error(ex.ToString());
}
return CharacterList;
}
...............................
// need an other class
public class CharacterContainer
{
public int a_index { get; set; }
public int a_user_index { get; set; }
public string a_name { get; set; }
public string a_nick { get; set; }
public int a_enable { get; set; }
}
................................
// how to use it
int UserID = 2032; // 2032 is the user Demo from ur starter packer
List<CharacterContainer> Characters = mySQL.Get_CharacterList(UserID);
for (int c = 0; c < Characters.Count; c++)
{
lock (_lock3)
{
int CharID = Characters[c].a_index;
string CharName = Characters[c].a_nick;
if (Characters[c].a_enable != 0)
{
Console.writeline("CharID: " +CharID + " UserName: " + UserName + " CharName:" + CharName);
}
}
}

