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

首頁 > 編程 > .NET > 正文

在.NET中調用DataWindow操作數據庫

2024-07-10 13:03:33
字體:
來源:轉載
供稿:網友
  • 本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。
  • 在.net中調用datawindow操作數據庫

    sybase在2004/1/19日推出了pb 10 beta1版本,其中包含datawindow.net 1.0,這真是一個另人興奮的消息! 在pb市場日益萎縮的今天,在.net大行其道的今天sybase公司終于推出了datawindow.net,它支持datawindow絕大部份原有事件和屬性,pb技術終于可以重新又派上用場了!!

    下過來安裝程序,便急不可待的在vs.net2003下面做了一個簡單的例子,發現真的很好用!源代碼、界面如下:



    using system;
    using system.drawing;
    using system.collections;
    using system.componentmodel;
    using system.windows.forms;

    namespace cjgl.report
    {
    /// <summary>
    /// datawindowtest 的摘要說明。
    /// </summary>
    public class datawindowtest : system.windows.forms.form
    {
    private sybase.datawindow.datawindowcontrol dw;
    private sybase.datawindow.transaction trans;
    private system.windows.forms.button btnretrieve;
    private system.windows.forms.button btndelete;
    private system.windows.forms.button btninsert;
    private system.windows.forms.button btnsave;
    private system.componentmodel.icontainer components;

    public datawindowtest()
    {
    //
    // windows 窗體設計器支持所必需的
    //
    initializecomponent();

    //
    // todo: 在 initializecomponent 調用后添加任何構造函數代碼
    //


    }

    /// <summary>
    /// 清理所有正在使用的資源。
    /// </summary>
    protected override void dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.dispose();
    }
    }
    base.dispose( disposing );
    }

    #region windows 窗體設計器生成的代碼
    /// <summary>
    /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
    /// 此方法的內容。
    /// </summary>
    private void initializecomponent()
    {
    this.components = new system.componentmodel.container();
    this.btnretrieve = new system.windows.forms.button();
    this.btndelete = new system.windows.forms.button();
    this.btninsert = new system.windows.forms.button();
    this.dw = new sybase.datawindow.datawindowcontrol();
    this.trans = new sybase.datawindow.transaction(this.components);
    this.btnsave = new system.windows.forms.button();
    this.suspendlayout();
    //
    // btnretrieve
    //
    this.btnretrieve.anchor = ((system.windows.forms.anchorstyles)((system.windows.forms.anchorstyles.bottom | system.windows.forms.anchorstyles.right)));
    this.btnretrieve.location = new system.drawing.point(360, 297);
    this.btnretrieve.name = "btnretrieve";
    this.btnretrieve.tabindex = 1;
    this.btnretrieve.text = "retrieve";
    this.btnretrieve.click += new system.eventhandler(this.btnretrieve_click);
    //
    // btndelete
    //
    this.btndelete.anchor = ((system.windows.forms.anchorstyles)((system.windows.forms.anchorstyles.bottom | system.windows.forms.anchorstyles.right)));
    this.btndelete.location = new system.drawing.point(260, 296);
    this.btndelete.name = "btndelete";
    this.btndelete.tabindex = 2;
    this.btndelete.text = "delete";
    this.btndelete.click += new system.eventhandler(this.btndelete_click);
    //
    // btninsert
    //
    this.btninsert.anchor = ((system.windows.forms.anchorstyles)((system.windows.forms.anchorstyles.bottom | system.windows.forms.anchorstyles.right)));
    this.btninsert.location = new system.drawing.point(152, 295);
    this.btninsert.name = "btninsert";
    this.btninsert.tabindex = 3;
    this.btninsert.text = "insert";
    this.btninsert.click += new system.eventhandler(this.btninsert_click);
    //
    // dw
    //
    this.dw.anchor = ((system.windows.forms.anchorstyles)((((system.windows.forms.anchorstyles.top | system.windows.forms.anchorstyles.bottom)
    | system.windows.forms.anchorstyles.left)
    | system.windows.forms.anchorstyles.right)));
    this.dw.datawindowobject = "dw_customer";
    this.dw.librarylist = "d://program files//sybase10//datawindow builder 1.0//dwb100.pbl";
    this.dw.location = new system.drawing.point(5, 5);
    this.dw.name = "dw";
    this.dw.scrollbars = system.windows.forms.scrollbars.both;
    this.dw.size = new system.drawing.size(432, 280);
    this.dw.tabindex = 4;
    this.dw.text = "datawindowcontrol1";
    this.dw.typeofdatawindow = sybase.datawindow.datawindowtype.grid;
    //
    // trans
    //
    this.trans.database = "asademo9.dba";
    this.trans.dbms = sybase.datawindow.dbmstype.oledb;
    this.trans.dbparameter = "provider=/'asaprov.90/'";
    this.trans.password = "sql";
    this.trans.servername = "asademo9";
    this.trans.userid = "dba";
    //
    // btnsave
    //
    this.btnsave.anchor = ((system.windows.forms.anchorstyles)((system.windows.forms.anchorstyles.bottom | system.windows.forms.anchorstyles.right)));
    this.btnsave.location = new system.drawing.point(46, 296);
    this.btnsave.name = "btnsave";
    this.btnsave.tabindex = 5;
    this.btnsave.text = "&save";
    this.btnsave.click += new system.eventhandler(this.btnsave_click);
    //
    // datawindowtest
    //
    this.autoscalebasesize = new system.drawing.size(6, 14);
    this.clientsize = new system.drawing.size(444, 333);
    this.controls.add(this.btnsave);
    this.controls.add(this.dw);
    this.controls.add(this.btninsert);
    this.controls.add(this.btndelete);
    this.controls.add(this.btnretrieve);
    this.name = "datawindowtest";
    this.text = "利用datawindow.net設計";
    this.resumelayout(false);

    }
    #endregion

    private void btnretrieve_click(object sender, system.eventargs e)
    {
    try
    {
    if ( !trans.isconnected)
    {
    trans.connect();
    }
    dw.settransobject(trans);
    dw.retrieve();

    }
    catch( sybase.datawindow.dberrorexception ee)
    {
    messagebox.show("數據庫連接出錯!"+ee.sqlerrortext);
    return;
    }
    }

    private void btninsert_click(object sender, system.eventargs e)
    {
    //插入一行
    int insertrow = dw.insertrow(0);
    dw.scroll(insertrow);
    //賦初值
    dw.setitemdouble(insertrow,"id",9999);
    dw.setitemstring(insertrow,"fname","huang");
    dw.setitemstring(insertrow,"lname","yong");
    dw.setitemstring(insertrow,"address","changsha");
    dw.setitemstring(insertrow,"city","changsha");
    }

    private void btndelete_click(object sender, system.eventargs e)
    {
    dw.deleterow(dw.currentrow);
    }

    private void btnsave_click(object sender, system.eventargs e)
    {
    try
    {
    dw.update();
    trans.commit();
    }
    catch (sybase.datawindow.dberrorexception ee)
    {
    messagebox.show("更新不成功!原因:"+ee.sqlerrortext);
    trans.rollback();
    }
    catch (sybase.datawindow.datawindownotcreatedexception ee)
    {
    messagebox.show("數據窗口還沒有創建!");
    trans.rollback();
    }
    catch(sybase.datawindow.methodfailureexception ee)
    {
    messagebox.show("更新不成功!原因:"+ee.message.tostring());
    trans.rollback();
    }
    }

    }
    }
    通過pb,或datawindow builder創建pbl庫和datawindow對象后,就像在pb中操作一樣,指定pbl庫位置和datawindow控件相關連datawindow對象,就可對datawindow進行相關的操作如dw.settransobject(trans);dw.retrieve();怎么樣?對原pb
    程序員來說很熟悉吧!

    上一篇:ADO.NET入門(4)

    下一篇:ADO.NET入門(1)

    發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 黄石市| 内黄县| 长阳| 牟定县| 大石桥市| 饶河县| 太保市| 江口县| 会理县| 抚宁县| 太保市| 调兵山市| 龙南县| 九龙坡区| 晋城| 化州市| 鸡泽县| 杂多县| 绿春县| 花莲县| 高碑店市| 高陵县| 四川省| 汝城县| 芮城县| 嘉兴市| 宽甸| 曲沃县| 游戏| 南陵县| 黎平县| 甘泉县| 蒙自县| 岐山县| 闽清县| 江口县| 喜德县| 珠海市| 象州县| 桦南县| 蛟河市|