我弄不清楚有什麼問題,我查了一下其他問題。 我在文本框中得到以下信息: 「mysql.data.mysqlclient.mysqlcommand」C#,MySql Select語句
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();
等
您需要將.SingleOrDefault()添加到getNome.SingleOrDefault()。ToString()或Even ExecuteScalar()的末尾,具體取決於您想要的內容 – jbutler483 2014-11-24 10:03:17