这是一个使用数据库的注册应用程序的一段代码。因为我可以说我知道面向对象的基本原理,所以我理解这个代码除了第一行。 一个对象(reader)如何成为另一个对象(cmd1)与另一个类(SqlCommand)的方法(ExecuteReader())?我希望我能创建一个对象的唯一方法就是像这样写(std :: object class = new class())。 这个被解释的链接也会受到欢迎。这条线是干什么的?
using(SqlDataReader reader = cmd1.ExecuteReader())
{
if (reader.Read())
{
reader.Close();
if (textBox4.Text == textBox5.Text)
{
using (SqlCommand cmd = new SqlCommand("UPDATE info SET [email protected] WHERE [email protected] AND [email protected]", conn))
{
cmd.Parameters.AddWithValue("@Password", textBox4.Text);
cmd.Parameters.AddWithValue("@Id", textBox3.Text);
cmd.Parameters.AddWithValue("@Password1", textBox2.Text);
cmd.ExecuteNonQuery();
}
MessageBox.Show("Password has been changed");
}
else
MessageBox.Show("The new password doesn't match the one written in repeat the new password blank space ");
}
else
MessageBox.Show("Wrong Id or Password");
}
你知道方法如何返回一个值,如int或字符串?他们也可以返回对象的实例。 ExecuteReader返回一个'SqlReader'对象的实例。 '使用'块使用该对象,然后一旦该块完成,它就摆脱该对象。 – sab669
方法可以返回对象。如果每个返回类型必须是“无效”的,那么写一个面向对象的系统是相当困难的。 – David