-- sqlError 처리
//Connection //Data Reader SqlErrorCollection sec = se.Errors; |
--sqlConnectionWithUsing
public partial class FrmSqlConnectionWithUsing : System.Web.UI.Page { private string ConnectionString; //필드 : 데이터베이스 연결문자열 저장 //생성자(Ctor + 탭 + 탭) public FrmSqlConnectionWithUsing() { ConnectionString = "server=.;database=Market;uid=Market;pwd=1234;"; } protected void Page_Load(object sender, EventArgs e) { //Empty } protected void btnConnection1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(ConnectionString); con.Open(); this.lblDisplay.Text = "연결완료"; con.Close(); //using구문 사용하면 생략 가능 } protected void btnConnection2_Click(object sender, EventArgs e) { //using()안에서 생성된 DB는 using 구문이 끝나면 자동으로 닫힌다. using (SqlConnection con = new SqlConnection(ConnectionString)) { con.Open(); this.lblDisplay.Text = "연결완료"; } //using 구문의 마지막 } 가 실행되면 ,자동으로 Close되므로 생략 가능 } } |
'.Net Project > ADO.NET 3.5' 카테고리의 다른 글
05장 ADO.Net 카테고리 추가,리스트,뷰(CategoryAdd,List,View) (0) | 2009.09.28 |
---|---|
05장 ADO.NET 데이터베이스 DB 바로 연결하여 웹 상에 출력 (0) | 2009.09.25 |
04장 ADO.NET Web.Config 파일에 있는 섹션에 있는 값 가져오기 (0) | 2009.09.25 |
03장 ADO.NET Connection 복습 (0) | 2009.09.25 |
01장 ADO.NET (DB 입출력 관련된 모든 명령어들의 집합) (0) | 2009.09.24 |