程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 設計模式(C#) - 提供者模式(Provider Pattern)(7)

設計模式(C#) - 提供者模式(Provider Pattern)(7)

編輯:關於C語言

Web.config

<?XML version="1.0" encoding="utf-8"?>
< configuration>
 <configSections>
  <section name="MessageProvider" type="Pattern.Provider.MessageProviderConfigurationSection, Pattern.Provider" />
 </configSections>
 <MessageProvider defaultProvider="SqlMessageProvider">
  <providers>
   <add name="XmlMessageProvider" type="Pattern.Provider.XmlMessageProvider, Pattern.Provider" connectionStringName="XMLConnection" />
   <add name="SqlMessageProvider" type="Pattern.Provider.SqlMessageProvider, Pattern.Provider" connectionStringName="SqlConnection" />
  </providers>
 </MessageProvider>
 <connectionStrings>
  <add name="SqlConnection" connectionString="server=.;database=db;uid=sa;pwd=sa" />
  <add name="XmlConnection" connectionString="XMLPath" />
 </connectionStrings>
< /configuration>

Test

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Pattern.Provider;

public partial class Provider : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
    Response.Write(Message.Insert(new MessageModel("插入", DateTime.Now)));
    Response.Write("<br />");
    Response.Write(Message.Get()[0].Message + " " + Message.Get()[0].PublishTime.ToString());
  }
}

運行結果

True

SQL方式,連接字符串是server=.;database=db;uid=sa;pwd=sa 2007-1-22 8:21:44

OK

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved