Presentation is loading. Please wait.

Presentation is loading. Please wait.

부산대학교 산업공학과 대학원 Department of Industrial Engineering at PNU. -1- Copyright © 2008 Chang-bong Kim 하병현교수님 ASP.NET & MS SQL Server 이름 : 김 창 봉 학번 : 200893192.

Similar presentations


Presentation on theme: "부산대학교 산업공학과 대학원 Department of Industrial Engineering at PNU. -1- Copyright © 2008 Chang-bong Kim 하병현교수님 ASP.NET & MS SQL Server 이름 : 김 창 봉 학번 : 200893192."— Presentation transcript:

1 부산대학교 산업공학과 대학원 Department of Industrial Engineering at PNU. -1- Copyright © 2008 Chang-bong Kim 하병현교수님 ASP.NET & MS SQL Server 이름 : 김 창 봉 학번 : Review: 0 날짜 : 표지

2 Department of Industrial Engineering at PNU. -2- Copyright © 2008 Chang-bong KimContents Microsoft.NET Framework Microsoft Visual Studio.NET Tool  Visual Basic.NET  Visual C++  C#.NET  Etc… Microsoft ASP.NET WebMatrix  WebDeveloper Microsoft.NET Basic Language  Visual Basic.NET  C#.NET

3 Department of Industrial Engineering at PNU. -3- Copyright © 2008 Chang-bong KimContents ASP.NET with Visual Studio.NET  *.asp -> *.aspx  Web Form? Server Control  Add Code to Web Form  Event Procedure  Code Behind (*.aspx.vb / *.aspx.cs)  Page Treatment Event  Error Treatment (Tracing/Debugging)  Validation Controls  User Controls  Database Connection  ADO -> ADO.NET DataSet DataReader Access to Stored Procedure of SQL Server Using ADO.NET

4 Department of Industrial Engineering at PNU. -4- Copyright © 2008 Chang-bong KimContents GuestBook & Web D/B  Design D/B  Create User to login D/B  Design Web Form  Coding  Etc…

5 Department of Industrial Engineering at PNU. -5- Copyright © 2008 Chang-bong Kim Introduction to.NET Framework.NET Framework?.NET Framework.NET Building Block Services.NET Enterprise Servers Visual Studio.NET Windows.NET

6 Department of Industrial Engineering at PNU. -6- Copyright © 2008 Chang-bong Kim Introduction to.NET Framework Framework, Languages and Development Tools

7 Department of Industrial Engineering at PNU. -7- Copyright © 2008 Chang-bong Kim Introduction to.NET Framework Advantages Support to Web Standard  HTTP/XML/SOAP/XSLT etc Use any Language  C#  VB.NET  C++  Etc (FORTRAM, COBOL…) Easy to Develop  Visual Studio.NET

8 Department of Industrial Engineering at PNU. -8- Copyright © 2008 Chang-bong Kim Introduction to.NET Framework Development Languages C/C++ Internet Web GUI Age of PC Large Host Env. Web Service

9 Department of Industrial Engineering at PNU. -9- Copyright © 2008 Chang-bong Kim Introduction to.NET Framework Enterprise Environment based on.NET

10 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Introduction to ASP.NET What’s ASP.NET? ASP(Active Server Page)  ASP.NET  *.asp  *.aspx  Interpret  Interpret + Compile Windows Style Programming (Drag & Drop Controls) Web Forms for ASP.NET Web Page All of the.NET Language are useable for ASP.NET Web Application Program  Visual Basic.NET, C# Support XML Web Service (Information exchange in a distributed environment)

11 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Introduction to ASP.NET ASP.NET Web Application Program Web Forms(web page) or.aspx page Code Behind Page (old *.asp is Interpret language) Web.config File (environment composition file) Global.aspx File (application level event treatment) Web Services  The Core of ASP.NET  Use Client  Make-up Service Caching  Speed-up Web Page (after first request) Database Connectivity

12 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Introduction to ASP.NET ASP.NET Execution Model Interpret

13 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Languages based on.NET Support Multi-Language on.NET.NET Framework supports Multi-Language  Microsoft Visual J#.NET  Microsoft Jscript.NET  COBOL  Pascal  C  Etc Advantages of Multi-Language Support  Code Reuse  One and same API access for all language of.NET  Possible to use all of the.NET functions even though use one language

14 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Languages based on.NET CLR(Common Languages Runtime) All of the.NET Languages use just one Runtime (same as gate and layer) Thread and Memory Management Solution for the DLL Version problems Components of the CLR  Class Loader (meta data)  MSIL to Native Compilers (C#, C++ and VB  Native Compiler)  Code Manager  Garbage Collector (release class and data memory if not use)  Security Engine  Debug Engine  Type Checker (check variable type)  Exception Manager  Thread Support  COM marshaler .NET Framework Class Library Support

15 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Languages based on.NET Compile and Execution based on CLR HTML JIT Compiler

16 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Languages based on.NET What’s Namespace? A collection for related to classes To prevent naming such things Use with Visual Basic.NET  Import System.Data.SqlClient Use with C#  Using System.Data.SqlClient

17 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Introduction to Visual Studio.NET Necessity of the Visual Studio.NET Use just one IDE (integrated development environment) for many language and project Use many programming language for one PROJECT (ex, web site) Use one solution for many project Integration of web browser Support debugging Support user defined Interface  VB, C#..

18 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Introduction to Visual Studio.NET Create First Page (demo) New Project  Visual C# Projcet (use ASP.NET template) Check solution files & IIS (inetmgr)

19 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Information of ASP.NET ASP.NET Basic Skills Client Script  HTML  CSS  JavaScript XSLT (Extensible Stylesheet Language Transformation) ASP Windows Xp/.NET Skills SQL Server

20 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Information of ASP.NET Related Site msdn.microsoft.com

21 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Development of Web Application Steps for development of web application Create Project Design Interface Coding Test & Debugging Release Distribution Web Application Design

22 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Department of Industrial Engineering at PNU Copyright © 2008 Chang-Bong, Kim GuestBook D/B Layout of GuestBook

23 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim GuestBook D/B Design GuestBook D/B Create New DB (ASP_NET) Create User (ID: cbkim, Password: solution) Create Table create table dbo.GuestBook ( Num Int Identity(1,1) Primary key not null, Name varchar(25) not null, Varchar(50) null, Content Text not null, PostDate DateTime Default GetDate(), PostIP VarChar(15) not null, Password varchar(20) not null ) Insert Data Insert GuestBook(Name, , Content, PostIP, Password) Values('ChangBong', 'Come back', '127,12,1,1', '1234') Query Select * From GuestBook

24 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim GuestBook D/B Use Procedure Create Procedure for Data save Create Procedure varchar(20) As Insert GuestBook(Name, , Content, PostIP, Password)

25 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim GuestBook D/B Use Procedure Create Procedure for Data save Create Procedure dbo.sp_GuestBookList AS Select Num, Name, , Content, PostIP From GuestBook Order By Num Desc Test Procedure 1.sp_GuestBookList 2.Exec sp_GuestBookList //use Exec command 3.Execute sp_GuestBookList

26 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim GuestBook D/B Design Web Forms

27 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim GuestBook D/B D/B Access using DataReader Write Namespace  using System.Data.SqlClient; Write Page_Load Function  if(!Page.IsPostBack){  ReadData(); //data output method  } Write DB access code private void ReadData() { SqlConnection objCon=new SqlConnection(); objCon.ConnectionString= "server=(local); database=ASP_NET; User ID=cbkim; Password=solution"; objCon.Open(); SqlCommand objCmd = new SqlCommand(); objCmd.Connection=objCon; objCmd.CommandText= "Select * From GuestBook Order By Num Desc"; SqlDataReader objDr=objCmd.ExecuteReader(); this.dgGuestBook.DataSource=objDr; this.dgGuestBook.DataBind(); objCon.Close(); }

28 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim GuestBook D/B Query Result in I/E

29 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim GuestBook D/B D/B Access using DataSet private void ReadData() { SqlConnection objCon=new SqlConnection(); objCon.ConnectionString= "server=(local); database=ASP_NET; User ID=cbkim; Password=solution"; objCon.Open(); SqlCommand objCmd = new SqlCommand(); objCmd.Connection=objCon; objCmd.CommandText= "Select * From GuestBook Order By Num Desc"; // Use DataSet objCmd.CommandType=CommandType.Text; SqlDataAdapter objDa=new SqlDataAdapter(); objDa.SelectCommand=objCmd; DataSet objDs=new DataSet(); objDa.Fill(objDs, "GuestBook"); this.dgGuestBook.DataSource=objDs; this.dgGuestBook.DataBind(); }

30 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim GuestBook D/B D/B Access using Stored Procedure private void ReadData() { SqlConnection objCon=new SqlConnection(); objCon.ConnectionString= "server=(local); database=ASP_NET; User ID=cbkim; Password=solution"; objCon.Open(); SqlCommand objCmd = new SqlCommand(); objCmd.Connection=objCon; objCmd.CommandText= "sp_GuestBookList"; objCmd.CommandType=CommandType.StoredProcedure; SqlDataAdapter objDa=new SqlDataAdapter(); objDa.SelectCommand=objCmd; DataSet objDs=new DataSet(); objDa.Fill(objDs, "GuestBook"); this.dgGuestBook.DataSource=objDs; this.dgGuestBook.DataBind(); }

31 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim GuestBook D/B D/B Access using Inline SQL private void btnSubmit_Click(object sender, System.EventArgs e) { SqlConnection objCon = new SqlConnection(); objCon.ConnectionString="server=(local); database=ASP_NET; User ID=cbkim; Password=solution"; objCon.Open(); SqlCommand objCmd = new SqlCommand(); objCmd.Connection=objCon; //" + txtName.Text +" objCmd.CommandText= "Insert GuestBook(Name, , Content, PostIP, Password) Values('" + txtName.Text +"', '" + txt .Text +"', '" + txtContent.Text +"', '" + Request.UserHostAddress +"', '" + txtPassword.Text +"')"; objCmd.CommandType= CommandType.Text; objCmd.ExecuteNonQuery(); objCon.Close(); ReadData(); } Double Submit Button and add following codes  Not easy to read code

32 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim GuestBook D/B The Result of Input Data using Inline SQL

33 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim GuestBook D/B Add Validation Check Code

34 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim GuestBook D/B Using SQL Parameter for D/B Input private void btnSubmit_Click(object sender, System.EventArgs e) { SqlConnection objCon = new SqlConnection(); objCon.ConnectionString= "server=(local); database=ASP_NET; User ID=cbkim; Password=solution"; objCon.Open(); SqlCommand objCmd = new SqlCommand(); objCmd.Connection=objCon; objCmd.CommandText="Insert GuestBook(Name, , Content, PostIP, Password) objCmd.CommandType= CommandType.Text; SqlDbType.VarChar, 25); SqlDbType.VarChar, 25); SqlDbType.Text); SqlDbType.VarChar, 15); SqlDbType.VarChar, 20); objCmd.ExecuteNonQuery(); objCon.Close(); ReadData(); }

35 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Department of Industrial Engineering at PNU Copyright © 2008 Chang-Bong, Kim GuestBook D/B Using Stored Procedure for D/B Input private void btnSubmit_Click(object sender, System.EventArgs e) { SqlConnection objCon = new SqlConnection(); objCon.ConnectionString= "server=(local); database=ASP_NET; User ID=cbkim; Password=solution"; objCon.Open(); SqlCommand objCmd = new SqlCommand(); objCmd.Connection=objCon; objCmd.CommandText= "sp_GuestBookInsert"; objCmd.CommandType = CommandType.StoredProcedure; SqlDbType.VarChar, 25); SqlDbType.VarChar, 25); SqlDbType.Text); SqlDbType.VarChar, 15); SqlDbType.VarChar, 20); " "); objCmd.ExecuteNonQuery(); objCon.Close(); ReadData(); }

36 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim GuestBook D/B Add Page Index to GuestBook Change Attributes  AllowPaging=True  PageSize=5  Mode=NumaricPages (In PagerStyle) Add Event  “PageIndexChanged” Add Code private void dgGuestBook_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e) { this.dgGuestBook.CurrentPageIndex=e.NewPageIndex; ReadData(); }

37 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim GuestBook D/B Result of the Page Index

38 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Web D/B Concept Write.aspx Delete.aspx Mosidy.aspx MS SQL Server 2005 List.aspx View.aspx

39 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Web D/B Design Web D/B Create New DB (web) Create User (ID: web, Password: web12345) Create Table Create Table dbo.Basic ( Num Int Identity(1,1) Primary key not null, Name varchar(25) not null, Varchar(100) null, Title varchar(150) not null, PostDate DateTime Default GetDate() not null, PostIP VarChar(15) not null, Content Text not null, Password varchar(20) not null, ReadCount Int Default 0, Encoding varchar(10) not null, Homepage varchar(100) null, ModifyDataDatetime null, MidifyIPvarchar(15) null )

40 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Insert Data Insert Basic (Name, , Title, PostIP, Content, Password, Encoding, Homepage) Values ('kim', 'test kim', ' ', 'context', '1234', 'text','http://pusan.ac.kr'); Query Test Select * From Basic Web D/B Design Web D/B

41 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Web D/B Design Web Form

42 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Web D/B Write Source Code – Write.aspx Add Namespace  using System.Data.SqlClient; Add to Page_Load Function if(!Page.IsPostBack) { ArrayList ar=new ArrayList(); ar.Add("Text"); ar.Add("Html"); lstEncoding.DataSource=ar; lstEncoding.DataBind(); }

43 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Department of Industrial Engineering at PNU Copyright © 2008 Chang-Bong, Kim private void btnSave_Click(object sender, System.EventArgs e) { SqlConnection objCon=new SqlConnection(); objCon.ConnectionString= "server=(local); database=Web; User ID=web; Password=web12345"; objCon.Open(); SqlCommand objCmd = new SqlCommand(); objCmd.Connection=objCon; //Inline SQL : " + variable +" objCmd.CommandText= "Insert Basic (Name, , Title, PostIP, Content, Password, Encoding, Homepage) Values ('" + txtName.Text + "', '" + txt .Text + "', '" + txtTitle.Text + "', '" + Request.UserHostAddress + "', '" + this.txtContent.Text +"', '" + txtPassword.Text +"', '" + this.lstEncoding.SelectedItem.Value +"', '" + txtHomepage.Text +"'); "; //Insert command objCmd.CommandType=CommandType.Text; objCmd.ExecuteNonQuery(); objCon.Close(); //Response.Redirect("./List.aspx"); } Web D/B Write Source Code – Write.aspx

44 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Web D/B Add Data Grid

45 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Web D/B Write Source Code-List.aspx private void Page_Load(object sender, System.EventArgs e) { if(!Page.IsPostBack) { ReadData(); //data output method } private void ReadData() { //connection SqlConnection objCon=new SqlConnection(); objCon.ConnectionString= "server=(local); database=Web; User ID=web; Password=web12345"; objCon.Open(); //command SqlCommand objCmd = new SqlCommand(); objCmd.Connection=objCon; objCmd.CommandText= "Select * From Basic Order By Num Desc"; objCmd.CommandType=CommandType.Text; //Data Adapter + Data Set SqlDataAdapter objDa=new SqlDataAdapter(); objDa.SelectCommand=objCmd; DataSet objDs=new DataSet(); objDa.Fill(objDs, "Basic"); //output this.DataGrid1.DataSource=objDs.Tables["Basic"].DefaultView; this.DataGrid1.DataBind(); }

46 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Web D/B Write Source Code-List.aspx private void btnWrite_Click(object sender, System.EventArgs e) { Response.Redirect("./Write.aspx"); }

47 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Web D/B Modify Html Code for List Link-List.aspx. BackColor="White" CellPadding="4" AutoGenerateColumns="False">

48 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Web D/B Add code to View.aspx using System.Data.SqlClient; protected string strNum=""; private void Page_Load(object sender, System.EventArgs e) { strNum=Request.QueryString["Num"]; //index value if(strNum==null) { Response.Redirect("./List.aspx"); } else { if(!Page.IsPostBack) ReadData(); } private void btnList_Click(object sender, System.EventArgs e) { Response.Redirect("./List.aspx"); }

49 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim private void ReadData() { //connection SqlConnection objCon=new SqlConnection(); objCon.ConnectionString= "server=(local); database=Web; User ID=web; Password=web12345"; objCon.Open(); //command SqlCommand objCmd = new SqlCommand(); objCmd.Connection=objCon; //add read count objCmd.CommandText="Update Basic Set ReadCount=ReadCount+1 Where Num="+strNum; objCmd.CommandType=CommandType.Text; objCmd.ExecuteNonQuery(); //Query for read objCmd.CommandText= "Select * From Basic Where Num=" + strNum; objCmd.CommandType=CommandType.Text; //data reader SqlDataReader objDr=objCmd.ExecuteReader(); //output if(objDr.Read()) { this.lblTitle.Text=objDr["Title"].ToString(); this.lblNum.Text=objDr["Num"].ToString(); this.lblName.Text=objDr["Name"].ToString(); this.lbl .Text=objDr[" "].ToString(); this.lblPostDate.Text=objDr["PostDate"].ToString(); this.lblReadCount.Text=objDr["ReadCount"].ToString(); this.lblContent.Text=objDr["Content"].ToString().Replace("\r\n", " "); } //close objDr.Close(); objCon.Close(); objCon=null; } Web D/B Add code to View.aspx

50 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Web D/B The result of View.aspx List.aspx View.aspx

51 Department of Industrial Engineering at PNU Copyright © 2008 Chang-bong Kim Web D/B Demo… List.aspx Write.aspx View.aspx Modify.aspx Delete.aspx Search.aspx


Download ppt "부산대학교 산업공학과 대학원 Department of Industrial Engineering at PNU. -1- Copyright © 2008 Chang-bong Kim 하병현교수님 ASP.NET & MS SQL Server 이름 : 김 창 봉 학번 : 200893192."

Similar presentations


Ads by Google