我不知道怎么了,我检查了其他有关此问题。
我在文本框中收到以下消息:“ 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
是唯一的)