Datawindow.net 系列二

Datawindow.Net version 2.0使用概要
1. 安装
先安装.net2005 ,框架版本2.0,然后安装DataWindow.Net 2.0组件及设计编译环境。
安装后在.net2005窗体设计时会出现Sybase DataWindow控件页签。

2. 使用
DataWindow控件可以直接在C#窗体中使用。

3. 设计DataWindow
在PB或DataWindow Designer设计环境中设计数据窗,并存到.pbl中,供程序调用。
发布后可以编译成.pbd文件格式(还未测试)。

4. C#中调用DataWindow
a) 窗体上创建一个Datawindow控件 起名为dw。
b)
Sybase.DataWindow.Transaction Trans = new Sybase.DataWindow.Transaction();
Trans.Dbms = Sybase.DataWindow.DbmsType.OleDb;//数据库连接方式
Trans.Password = "123";
Trans.UserID = "sa";
Trans.AutoCommit = false;
Trans.Lock = "RC";
Trans.DbParameter = “PROVIDER=''SQLOLEDB'',DATASOURCE=''xiancai'',
PROVIDERSTRING=''database=demo''”;//数据库连接串
Trans.Connect();//连接数据库
d) 显示数据窗
dw.LibraryList = “test.pbl”;//发布后使用.pbd文件
dw.DataWindowObject = "datawindowName";//数据窗名称
dw.SetTransaction(Trans );
dw.Retrieve();//显示数据窗
e) 关闭连接
Trans.Disconnect();
 ============or================================or===================
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
Sybase.DataWindow.AdoTransaction adTrans;
conn.ConnectionString = "Server=localhost;Initial Catalog=Northwind;User ID=sa;Password=sa;"//Provider=SQLOLEDB;
conn.Open();
adTrans = new Sybase.DataWindow.AdoTransaction(conn);
dw_1.LibraryList = "test.pbl";
dw_1.DataWindowObject = "datawindowName";
adTrans.BindConnection();
dw_1.SetTransaction(adTrans);
dw_1.Retrieve();
conn.Close();
5. c#中利用DataWindow控件操作数据
a) 添加
int row = this.dw.InsertRow(0);//插入一条记录
dw.SetRow(row);
dw.SetItemString(row,"ID",”100”);//给字段赋值
dw.SetItemString(row,"名称","name"); //给字段赋值
b) 删除
this.dw.DeleteRow( 1 );//删除第一行记录
c) 保存
this.dw.UpdateData( true, true );
Trans.Commit();//数据提交后才写入数据库中 
全部系列相关链接:
Datawindow.net系列之一 Datawindow.net系列之二 Datawindow.net系列之三 Datawindow.net系列之四 Datawindow.net系列之五 Datawindow.net系列之六 Datawindow.net系列之七 Datawindow.net系列之八 Datawindow.net系列之九 返回到本系列首页--Datawindow.net系列之一

你可能感兴趣的:(.NET,相关,Power,Builder)