国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

C#編寫ASP.NET組件

2024-07-10 13:07:21
字體:
來源:轉載
供稿:網友
  • 本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。
  • //訪問數據庫是每個程序員都想簡化的工作,通過組件來完成,新手也變高手...

    using system;
    using system.collections.generic;
    using system.text;
    using system.data;
    using system.configuration;
    using system.data.oracleclient;

    namespace netado
    {
        public class netdb
        {
            private string connstr="";
      private oracleconnection oraconn;

      public netdb()
      {
                connstr = configurationmanager.appsettings["oracle9iconnstr"];
       this.oraconn=new oracleconnection();
       if(connstr==null)
       {
         throw new exception("connectionstring is null");
       }
       this.oraconn.connectionstring=connstr;
      }

      public string connstring
      {
       get
       {
        return connstr;
       }
      }


      private void connectionprepare(bool ifbegin)
      {
       //檢查連接字符串
       if(oraconn.connectionstring==null)
       {
        throw new exception("oledbconnection's connectionstring is null,execute init()");
                   
       }
       //根據參數執行相關操作
       if(ifbegin==true)
       {
        if(oraconn.state==connectionstate.closed)
        {
         oraconn.open();
        }
       }
       else
       {
        if(oraconn.state==connectionstate.open)
        {
         oraconn.close();
        }
       }
      }


      public dataset runsqlreturnds(string sqlstring)
      {
       dataset ds=new dataset();
       try
       {
        connectionprepare(true);
        oraclecommand cmd=oraconn.createcommand();
        cmd.commandtext=sqlstring;
        oracledataadapter adapter=new oracledataadapter(cmd);
        adapter.fill(ds);
       }
       catch(exception ex)
       {
        throw new exception(ex.message);           
       }
       finally
       {
        connectionprepare(false);
       }
       return ds;
      }

      public int runsql(string sqlstring)
      {
       int rowcount=0;
       try
       {
        connectionprepare(true);
        oraclecommand cmd=oraconn.createcommand();
        cmd.commandtext=sqlstring;
        rowcount=(int)cmd.executenonquery();
       }
       catch(exception ex)
       {
        throw new exception(ex.message);           
       }
       finally
       {
        connectionprepare(false);
       }
       return rowcount;
      }
        }
    }
     

    //頁面調用
    using netado;

    public partial class _default : system.web.ui.page
    {
        netdb nd = new netdb();
        protected void page_load(object sender, eventargs e)
        {
            try
            {
                response.write(nd.connstring.tostring() + "<br>");

                dataset objectset = new dataset();
                objectset = nd.runsqlreturnds("select * from tblszman where rownum<=10");
                response.write(objectset.tables[0].rows.count.tostring() + "<br>");
                int s = nd.runsql("drop table temptu");
                response.write(s.tostring() + "<br>");
            }
            catch (exception ex)
            {
                response.write("錯誤信息:" + ex.message);
                response.end();
            } 
        }
    }

    發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 吕梁市| 天门市| 合川市| 蒲城县| 化州市| 寻乌县| 墨竹工卡县| 喀喇沁旗| 翼城县| 余庆县| 德庆县| 阜平县| 庆阳市| 福安市| 桐梓县| 武陟县| 板桥市| 邹城市| 凤庆县| 华容县| 鄱阳县| 顺平县| 浙江省| 桂平市| 瑞安市| 田阳县| 华坪县| 藁城市| 宣化县| 贵南县| 西华县| 固始县| 罗田县| 句容市| 瑞昌市| 林甸县| 贺州市| 奎屯市| 全椒县| 昌宁县| 囊谦县|