1 / 50

3 주 실습강의

3 주 실습강의. ASP.NET : Database 접근 2008 컴퓨터공학실험 (Ⅰ). Preface. 폼의 유효성 검사 : Field Validation RequiredFieldValidator RegularExpressionValidator ValidationSummary ASP.NET 에서 Access DB (MDB) 연결 / 조작 AccessDataSource (or SqlDataSource) GridView

jnina
Download Presentation

3 주 실습강의

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 3주 실습강의 ASP.NET :Database 접근 2008 컴퓨터공학실험(Ⅰ)

  2. Preface • 폼의 유효성 검사 : Field Validation • RequiredFieldValidator • RegularExpressionValidator • ValidationSummary • ASP.NET에서 Access DB (MDB) 연결 / 조작 • AccessDataSource (or SqlDataSource) • GridView • OleDbConnection, OleDbCommand,OleDbDataReader

  3. DB 테이블 create table cee_w3_board ( seq int identity (1, 1) not null primary key clustered, writer varchar (20) not null , pwd varchar (20) not null , email varchar (100) null , title varchar (200) not null , writedate smalldatetime not null default (getdate()), readed int not null default (0), mode tinyint not null , content varchar (8000) null )

  4. MS JetDB : 테이블 구조 • Access – 디자인 보기

  5. Write.aspx – 레이아웃

  6. Write.aspx 접근 방법

  7. Write.aspx – 웹폼 컨트롤 속성

  8. Write.aspx – Validation 컨트롤 속성

  9. Validator의 종류 / 기능

  10. Write.aspx – 데이터 컨트롤

  11. Write.aspx – 데이터 소스 구성 (1/3)

  12. Write.aspx – 데이터 소스 구성 (2/3)

  13. Write.aspx – 데이터 소스 구성 (3/3)

  14. Write.aspx – 데이터 컨트롤 속성 데이터 소스 구성을 통하지 않고, “데이터” - 각 쿼리 부분에 원하는 쿼리를 작성하여 설정을 완료할 수 있다. “동작”– DataSourceMode속성에는 DataSet과 DataReader가 있는데, GridView와 같은 컨트롤 에서는 DataSet을, ListBox와 같이 정렬, 페이징 등이 필요 없는 컨트롤에서는 DataReader로 설정하여 사용할 수 있다.

  15. Write.aspx – 쿼리문 입력

  16. Write.aspx – 파라메터 컬렉션 편집

  17. Write.aspx – 파라메터 컬렉션 편집

  18. Write.aspx – 코드 입력 및 완료 private void btnSubmit_Click(object sender, System.EventArgs e) { if (IsValid && Label1.Visible==false) { Sqldata.InsertParameters["write"].DefaultValue = txtWriter.Text; Sqldata.InsertParameters["pwd"].DefaultValue = txtPassword.Text; Sqldata.InsertParameters["email"].DefaultValue = txtEmail.Text; Sqldata.InsertParameters["title"].DefaultValue = txtTitle.Text; Sqldata.InsertParameters["writedate"].DefaultValue = DateTime.Now.ToString(); Sqldata.InsertParameters["content"].DefaultValue = txtContent.Text; Sqldata.InsertParameters["mode"].DefaultValue = rdoMode.SelectedIndex.ToString(); Sqldata.Insert(); Response.Redirect("list.aspx"); } } 만약 Parameter 연결을 했을 경우, 다음과 같이 짧은 코드로 완성이 가능하다. protected void Button_Submit_Click(object sender, EventArgs e) { if(IsValid) // 글 삽입 모드 { Sqldata.Insert(); Response.Redirect("list.aspx"); } }

  19. List.aspx – 개발 접근 순서

  20. List.aspx – 컨트롤 설정

  21. List.aspx – DataSource : Select 구문

  22. List.aspx – GridView 속성

  23. List.aspx – GridView 필드 설정

  24. List.aspx – 데이터 컨트롤 속성

  25. List.aspx – 데이터 컨트롤 속성

  26. List.aspx – 데이터 컨트롤 속성

  27. List.aspx – 자동 서식 지정

  28. List.aspx – 호출되는 메서드 작성 public partial class List : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { Response.Redirect("view.aspx?id=" + GridView1.SelectedValue.ToString()); } }

  29. View.aspx – 컨트롤 설정

  30. View.aspx 구현 접근 과정

  31. View.aspx – DB관련 개체 설정 • OleDbConnection 하나 • ConnectionString 설정 • OleDbCommand 1 • (Name) : dbCommandGetArticle • Connection : dbConnection • CommandText :SELECT writer,email,title,mode,content,readed,writeDate FROM cee_w3_board WHERE seq = ? • Parameters : 하나 추가ParameterName : seqSqlDbType : integer

  32. View.aspx – DB관련 개체 설정 • OleDbCommand 2 • (Name) : dbCommandUpdateReadCount • Connection : dbConnection • CommandText :UPDATE cee_w3_board SET readed=readed+1 WHERE seq = ? • Parameters : 하나 추가ParameterName : seqSqlDbType : integer

  33. View.aspx – DB관련 개체 설정 • OleDbCommand 3 • (Name) : dbCommandGetPrevArticle • Connection : dbConnection • CommandText :SELECT top 1 seq, title FROM cee_w3_board WHERE seq > ? ORDER BY seq ASC; • Parameters : 하나 추가ParameterName :seqSqlDbType : integer

  34. View.aspx – DB관련 개체 설정 • OleDbCommand 4 • (Name) : dbCommandGetNextArticle • Connection : dbConnection • CommandText :SELECT top 1 seq, title FROM cee_w3_board WHERE seq < ?ORDER BY seq DESC • Parameters : 하나 추가ParameterName : seqSqlDbType : integer

  35. View.aspx 세부 구현 (Page_Load : 1)

  36. View.aspx 세부 구현 (Page_Load: 2)

  37. Delete.aspx – 컨트롤 설정

  38. Delete.aspx – DB관련 개체 설정

  39. Delete.aspx – DB관련 개체 설정

  40. Delete.aspx – DB관련 개체 설정

  41. Delete.aspx – 소스 편집

  42. 글 수정 – Write.aspx 의재구성

  43. 글 수정 – Write.aspx 재구성 접근 방법

  44. 글수정 – DB관련 개체 추가(1/2) • OleDbCommand 1 • (Name) : dbCommandGetArticleForModify • Connection : dbConnection • CommandText :SELECT writer, email, title, content, mode FROM cee_w3_board WHERE seq = ? • Parameters : 하나 추가ParameterName : seqSqlDbType : integer

  45. 글수정 – DB관련 개체 추가(2/2) • OleDbCommand 2 • (Name) : dbCommandModifyArticle • Connection : dbConnection • CommandText :UPDATE cee_w3_board SET writer = ?, email = ?, title = ?, content = ?, mode = ? WHERE seq = ? AND pwd = ? • Parameters : 7개 추가

  46. 글 수정 – Write.aspx 구현 : Page_load (1)

  47. 글 수정 – Write.aspx 구현 : Page_load (2)

  48. 글 수정 – Write.aspx 세부 구현 : DataBind 사용

  49. 글 수정 – Write.aspx

  50. 글 수정 – Write.aspx

More Related