我会做这件事:
"select nome,cognome from Utenti where CodiceCliente = @codice"
然后在后面的代码中使用“ nome”中的值和“ cognome”中的值。有了PHP,在C#ASP.NET中有关联数组?
到目前为止,我一直使用两个不同的命令,但是现在很烦人。
例:
MySqlCommand getNome = new MySqlCommand("select Nome from Utenti where CodiceCliente = @codice", userConnection);
MySqlCommand getCognome = new MySqlCommand("select Cognome from Utenti where CodiceCliente = @codice", userConnection);
MySqlCommand getEmail = new MySqlCommand("select IndirizzoEmail from Utenti where CodiceCliente = @codice", userConnection);
getNome.Parameters.AddWithValue("@codice", codice);
getCognome.Parameters.AddWithValue("@codice", codice);
getEmail.Parameters.AddWithValue("@codice", codice);
userConnection.Open();
string nome = Convert.ToString(getNome.ExecuteScalar());
string cognome = Convert.ToString(getCognome.ExecuteScalar());
string email = Convert.ToString(getEmail.ExecuteScalar());
你能帮助我吗?
之前感谢,
Daniele
简单用法:
using(var connection = new MySqlConnection(myConnString))
{
var cmd = connection.CreateCommand();
cmd.CommandText = "select nome,cognome from Utenti where CodiceCliente = @codice";
cmd.Parameters.AddWithValue("@codice", value);
var reader = cmd.ExecuteReader();
while(reader.Read())
{
// here could be problems if database value is null
var nome = reader["nome"];
var cognome = reader["cognome"];
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句