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();
}
내 질문 : 나는매개 변수가있는 SqlCommand는 어떻게 작동합니까?
command.ExecuteNonQuery()
또는
command.ExecuteReader()
방법 명령 참조 새로 만든 SqlParameter
객체의 참조 또는 메모리 위치를 찾을 수를 쓸 때?
힙 메모리와 스택 메모리에서 이러한 개체 및 참조의 참조 그림을 그릴 수 있습니까? 아마 내 대답은 다음 이미지입니다
는 :
설명서를 검색하셨습니까? – astidham2003
매개 변수를 추가하는 다양한 방법으로 전혀 차이가 있다고 생각하게 만드는 요인은 무엇입니까? 컴파일러가 완성 될 즈음에 그들은 어쨌든 모두 같은 결과를 낼 수있는 것처럼 보입니다. 그리고 당신은 정말로 내가 그림을 그리기를 원하지 않습니다. – stuartd
정말 호기심을 느끼면 .NET 반사경을 사용하여 IL을 볼 수 있습니다. – reggaeguitar