public string InsertStudent(Student student)
{
string message = "";
SqlConnection connection = new SqlConnection(connectionString);
string query = "insert into Students values(@regNo, @name, @email, @departmentId)";
SqlCommand command = new SqlCommand(query, connection);
command.Parameters.Clear();
command.Parameters.Add("regNo", SqlDbType.VarChar, 50).Value = student.RegNo;
//////////////////or//////////////
command.Parameters.Add("name", SqlDbType.VarChar);
command.Parameters["name"].Value = student.Name;
command.Parameters.Add("email", SqlDbType.VarChar);
command.Parameters["email"].Value = student.Email;
command.Parameters.Add("departmentId", SqlDbType.Int);
command.Parameters["departmentId"].Value = student.DepartmentId;
connection.Open();
int rowAffected = command.ExecuteNonQuery();
connection.Close();
}
My question: when I write
command.ExecuteNonQuery()
or
command.ExecuteReader()
how command reference find out the references or memory locations of newly created SqlParameter
objects?
May you draw pictures of references of these objects and their relations in heap memory and stack memory?
probably my answer is following image: