Считывание данных определенного пользователя из базы (C#) - MySQL
Формулировка задачи:
Подскажите как считать по отдельности данные определенного пользователя с таблицы mysql в c#.
С начало я нахожу определенного пользователя.
Потом пытаюсь считать. По разному пробовал
значение hp в таблице mysql у меня int.
connection.Open();
provtabl = "SELECT count(*) from player where name = '" + label1.Text + "'";
command = new MySqlCommand(provtabl, connection);
int temp = Convert.ToInt16(command.ExecuteScalar());if (temp == 1)
{
MySqlDataReader rd = command.ExecuteReader();
while (rd.Read())
{
label5.Text = rd.GetInt32("hp").ToString();
или
label5.Text = rd["hp"].ToString();
или
label5.Text = rd.GetString("hp");
}
rd.Close();
connection.Close();
}Решение задачи: «Считывание данных определенного пользователя из базы (C#)»
textual
Листинг программы
int temp = 0;
connection = new MySqlConnection(connectionString);
connection.Open();
provtabl = "SELECT count(*) AS hp from player where name = '" + label1.Text + "'";
command = new MySqlCommand(provtabl, connection);
temp = Convert.ToInt16(command.ExecuteScalar());
if (temp == 1)
{
MySqlDataReader rd = command.ExecuteReader();
rd.Read();
label5.Text = rd.GetInt32("hp").ToString();
rd.Close();
connection.Close();
}