I am making an application where I scrape a certain website. The website has a bunch of players, and I scrape each one of their profile pages. Their profile pages contains information like Name, Level, World and Last Login date.
So I made an object called Player. And then I add all their data to a list.
public static List<Player> Players = new List<Player> { };
public class Player
{
public string Name { get; set; }
public string Sex { get; set; }
public string Vocation { get; set; }
public int Level { get; set; }
public int Achievements { get; set; }
public string World { get; set; }
public string LastLogin { get; set; }
public string AccountStatus { get; set; }
public int OnlineStatus { get; set; }
}
I add the data like this:
new Player { Name = playerName, Sex = playerSex, Vocation = playerVocation, Level = playerLevel, Achievements = playerAchievements, World = playerWorld, LastLogin = playerLastLogin, AccountStatus = playerAccountStatus, OnlineStatus = playerOnlineStatus };
I now want to add all the players to my MySQL database, but I cannot seem to understand how to insert the data.
I established a connection and I tried to SELECT data and it works fine. So my connection is not bad. But inserting seems to not work.
Here's my code I add to insert the data into the tables:
string connString = "Server=localhost;Port=3306;Database=rookstat;Uid=XXXXXXX;password=XXXXXX;";
MySqlConnection conn = new MySqlConnection(connString);
MySqlCommand command = conn.CreateCommand();
foreach (Player rooker in Players)
{
command.CommandText = "Insert into rookstayers (id, name, sex, vocation, level, achievements, world, lastlogin, accountstatus, onlinestatus) values('', rooker.Name, rooker.Sex, rooker.Vocation, rooker.Level, rooker.Achievements, rooker.World, rooker.LastLogin, rooker.AccountStatus, rooker.OnlineStatus)";
conn.Open();
command.ExecuteNonQuery();
}
conn.Close();
What am I doing wrong? I am unsure about the values i insert. Is it supposed to be rooker.Name or what?
"INSERT (..) VALUES (myvariable)"isn't the same as"INSERT (..) VALUES (" + myvariable + ")"