在.net中调用datawindow操作数据库

原创 2007年09月23日 23:08:00
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
程序员来说很熟悉吧!


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

vs2013中使用PB DataWindow .net

vs2013中简单使用PB DataWindow .net

DataWindow.net应用介绍(一)

Datawindow中文译名为数据窗口,是开发工具PowerBuilder(PB)的一个王牌组件,使用PB作为开发工具的,基本上都是冲着Datawindow 来的,它不仅可以用来显示数据,还可以实现数...

web datawindow.net 应用

  • 2009-09-25 15:29
  • 836KB
  • 下载

DataWindow.Net 2.5 9097

  • 2013-04-01 13:26
  • 59MB
  • 下载

asp.net使用SQLHelper操作数据库

http://www.cnblogs.com/nicStudio/archive/2011/01/19/1939206.html 使用控件,能够方便开发人员的开发和使用,但是很多情况下,不能使用控件来...

Datawindow.Net+2.5完美破解

  • 2015-05-07 20:50
  • 2.02MB
  • 下载

DataWindow.NET V2.0.rar

  • 2010-01-07 20:51
  • 14KB
  • 下载

C# ADO.NET的五个常用对象及数据库连接操作

C#中和数据库连接的操作时开发中必不可少的,而ADO.NET就是其中的关键技术之一。常见的ADO.NET有五个常用的对象: SqlConnection 数据库连接对象 SqlCommand 数据...

DataWindow.Net 2.5 EBF 18212 9097_1

  • 2013-04-01 13:32
  • 33.38MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)