1 / 15

.NET 資料庫實作

.NET 資料庫實作. 台南市教育局網路中心 在職教師校務行政系統程式開發 進階班 行政網路組 asp@mail.tn.edu.tw. 建立資料庫及 table. 1.Create DataBase---h 2. 設定帳號 h-h 3.create table. 建立資料庫元件. 1. 新增 com 目錄 2. 新增 component.class( 同 name space) 3. using System.Data; using System.Data.SqlClient; 4.public 5. 建立 num table.

helia
Download Presentation

.NET 資料庫實作

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. .NET資料庫實作 台南市教育局網路中心在職教師校務行政系統程式開發進階班行政網路組 asp@mail.tn.edu.tw

  2. 建立資料庫及table • 1.Create DataBase---h • 2.設定帳號h-h • 3.create table

  3. 建立資料庫元件 • 1.新增com目錄 • 2.新增component.class(同name space) • 3. using System.Data; using System.Data.SqlClient; • 4.public • 5.建立num table

  4. Web.Config • using System.Configuration; • ConfigurationSettings.AppSettings["ConnectionString"] • 資料庫connection string------設定 <appSettings> <add key="ConnectionString" value="server=localhost;uid=h;pwd=h;database=h" /> </appSettings>

  5. 建立store StoredProcedure CREATE procedure hinumSP ( @num int OUTPUT ) AS SELECT @num=num FROM hinum WHERE (id = 1) IF @@Rowcount > 0 UPDATE hinum SET num=num+1 WHERE id=1 GO

  6. public string hitnum(){}說明 • SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); • myCommand.CommandType = CommandType.StoredProcedure; • SqlParameter parameternum=new SqlParameter("@num", SqlDbType.Int,4); • parameternum.Direction=ParameterDirection.Output; • myCommand.ExecuteNonQuery(); • string numw=parameternum.Value.ToString();

  7. 引用建立元件 • 開啟left.ascx.cs編輯 • 加入以下code com.myData hit=new com.myData; string qqq=hit.hitnum(); hitnum.Text=qqq;//(輸出) • 開啟uc.aspx實測

  8. 建立add元件 • 建立收集資訊Web Form—add.aspx • 建立add元件 • 建立store StoredProcedure

  9. 引用add元件 • using System.Text; --------StringBuilder • using System.Web.Mail;----MailMessage • 講解ServerVariables HTTP_VIA HTTP_X_FORWARDED_FOR REMOTE_ADDR • SMTP oMsg.To=ConfigurationSettings.AppSettings["email"]; oMsg.From=txtname.Text+"<"+txtemail.Text+">"; oMsg.Cc=ConfigurationSettings.AppSettings["email"]; oMsg.Bcc=ConfigurationSettings.AppSettings["email"]; SmtpMail.Send(oMsg);

  10. 建立select Data元件(回傳DataSet) • 同前步驟spcreate class SqlDataAdapter oDa = new SqlDataAdapter(); DataSet oDs = new DataSet(); oCn.Open(); oDa.SelectCommand=oCmd; oDa.Fill(oDs,"test"); oCn.Close();

  11. 建立select.aspx • 加入DataGrid • Page_onload時引入Select元件 • DataBinding dg1.DataSource=ds; dg1.DataBind(); • 測試

  12. 建立Webservice • getData.asmx • 引用原元件select [WebMethod] public DataSet GetUserData() { }

  13. Add Web Reference(1)

  14. Add Web Reference(2)

  15. 引用Web Service • 建立ws.aspx • 引用web service如同使用資料庫元件簡單

More Related