본문 바로가기

IT/Web Programming

[ASP.NET] 스토어프로시저를 이용한 Record Read


네임스페이스 지정

using System.Data.SqlClient;

 

SqlConnection dbcon = new SqlConnection("디비연결자"); - db연결 객체 생성

SqlCommand cmd = new SqlCommand(); - 쿼리객체 생성

cmd.Connection = dbcon; - db연결

 

cmd.CommandType = CommandType.StoredProcedure; - 쿼리타입은 저장프로시저로..

 

dbcon.Open();

cmd.CommandText = "프로시저 네임"  - 쿼리문에 저장될 프로시저 이름

SqlDataReader reader = cmd.ExecuteReader(CommnadBehavior.CloseConnection);

- 쿼리문을 던져 레코드를 읽음

 

저장할 변수 및 컨트롤 속성 = reader[array].ToString();

- 문자형태로 변환된 컬럼내용을 저장

 

reader.Close();

dbcon.Close();

 

- 작업이 모두 끝난후 객체들을 모두 닫음