我不知道哪里出了问题,我已经检查了其他有关它的问题。 我在文本框中收到以下消息:“mysql.data.mysqlclient.mysqlcommand”
if (Session["Login"] != null)
{
string email = (string)Session["Login"];
MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionStringloginDb"].ConnectionString);
conn.Open();
MySqlCommand getNome = conn.CreateCommand();
getNome.CommandType = CommandType.Text;
getNome.CommandText = "SELECT nome_utente FROM utenti WHERE email = @email";
getNome.Parameters.AddWithValue("@email", email);
getNome.ExecuteNonQuery();
txtNome.Text = getNome.ToString();
conn.Close();
等等
最佳答案
getNome
是一个 MySqlCommand
,它不会覆盖 ToString
。因此,当您调用 getNome.ToString
时,您会获得完整的类型名称。你想要这个:
// getNome.ExecuteNonQuery(); <--- not this
txtNome.Text = (String)getNome.ExecuteScalar(); <--- but this
(假设 email
是唯一的)
关于C#、MySql Select语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27102083/