国产探花免费观看_亚洲丰满少妇自慰呻吟_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();
            } 
        }
    }

    發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 新泰市| 黔西| 乌拉特前旗| 驻马店市| 盈江县| 浠水县| 靖江市| 浦县| 霍林郭勒市| 依安县| 东源县| 大同县| 兴化市| 密云县| 凉城县| 蛟河市| 油尖旺区| 永兴县| 句容市| 黄梅县| 伊通| 弥勒县| 繁昌县| 德令哈市| 宁阳县| 新密市| 大理市| 霍州市| 衢州市| 广州市| 蓝田县| 新巴尔虎左旗| 乌兰县| 丹棱县| 兰州市| 中西区| 开阳县| 秦皇岛市| 巫溪县| 云林县| 玉山县|