1)SqlDataReader가 닫힐 때까지 출력 매개 변수를 검색 할 수없는 경우 이유는 무엇입니까? SqlDataReader의 사용되는 동안
는 연관된도록 SqlConnection은 SqlDataReader를 서빙 중이 및 다른 작업은 폐쇄 이외 SqlConnection이 수행 될 수 없다. 이는 SqlDataReader의 Close 메서드가 호출 될 때까지 발생합니다. 예를 들어, Close를 호출 할 때까지는 출력 매개 변수를 검색 할 수 없습니다. 상기 제 true이면
가, 왜 출력 매개 변수의 값을 검색 할 수는 다음 방법은 독자가 폐쇄되기 전에 :
public int Something()
{
using (SqlConnection con = new SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new SqlCommand("some_procedure", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@ID", SqlDbType.Int).Direction = ParameterDirection.Output;
con.Open();
cmd.ExecuteReader();
return (int)cmd.Parameters["@ID"].Value;
}
}
2)
넌 수 CommandText 속성을 다시 설정하고 SqlCommand 개체를 다시 사용하십시오. 그러나 새 명령이나 이전 명령을 실행하려면 먼저 SqlDataReader를 닫아야합니다.
왜 새 명령을 실행하기 전에 sqldatareader를 닫아야합니까? 첫 번째 질문에
고맙습니다
# 1의 경우, 당신은 'SqlDataReader'에 대한 문서를 매우 자세하게 게시하고 있습니다. 아직 사용중인 문서가 아닙니다. 이것은 문서와 모순되지 않으며 적용 할 수 없습니다. –
및 SqlDataReader는 어디에 있습니까? –
젠장 ... 오타 ... 나는 그것을 바로 잡을 것이다 – AspOnMyNet