vb6在vb.net中的记录集替换? [英] vb6's recordset replacement in vb.net?

查看:99
本文介绍了vb6在vb.net中的记录集替换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在vb6中,我可以使用ADO的记录集从数据库中检索数据,对数据进行工作,然后将修改发送回数据库。


我使用断开连接的记录集,并调用updatebatch将更新发送到

数据库。


在vb.net中,我使用datatable从数据库中检索数据并且工作

数据。下一步,将更新发送到数据库,对我来说是一个两难的问题。


如果我使用dataadapter发送更新,那么我必须提供插入,

更新,手动删除命令。


如果我使用tableadapter,那么我必须限制自己使用匹配的

键入的数据表。非常有限,因为我通常在我的select语句(或sql子查询)中执行sql join

,在网格上显示数据,

让用户修改,然后保存更改到数据库。使用

tableadapter,在事务数据中显示查找数据不再容易。


另一种方法是使用存储过程,但后来我必须使用支持存储过程的
数据库。我也更喜欢保持

数据库哑,并将所有逻辑存储在一个地方,即程序。


还有其他方法吗?或者我应该咬紧牙关并构建我的

自己的命令生成器?


-

Endy

解决方案

endy_tj写道:


>

有没有其他办法?或者我应该咬紧牙关并构建我的

自己的命令生成器?



我不使用数据适配器或表适配器。我有3个方法,一个用于插入,

更新和删除,它将占用任何表,并创建并运行相应的

命令。设置它需要一些工作;但是,一旦你拥有它,

任务就完成了。


VS.Net的工作方式(VB.Net/C# for这个解释是那种有点

用从服务器中选择的对象创建一个内存数据库

DB。如果您在服务器数据库上有相关表,并且想要从这些表中查看数据

,您将在

dataAdapter中使用select语句:


'' - 这些变量是全局的

dim da作为SqlDataAdapter,ds As Dataset,conn as SqlConnection

------- --------------------------------------

Private Sub Form1_Load( ...)句柄....

da =新SqlDataAdapter

ds =新数据集

da.SelectCommand = new SqlCommand

da.SelectComman.Connection = conn

da.InsertCommand = New sqlCommand

da.InsertCommand.Connection = conn

da .InsertCommand.Parameters.Add(" @ p1",...)

da.UpdateCommand = New SqlCommand

da.UpdateCommand.Connection = conn

da.UpdateCommand.Parameters.Add(" @ p1",...)

da.SelectCommand.CommandText =" Select * From tbl1"

da.Fill(ds," tblA")

datagridview1 .DataSource = ds.Tables(" tblA")

...

End Sub


Private Sub datagridview1CellValue_Changed(。 ..)句柄...

ds.Tables(" tblA")。行(e.RowIndex)(e.ColumnIndex)=

datagridview1.Rows(e .RowIndex)。细胞(e.columnIndex).Value


da.Update(ds," tblA")

End Sub

----------------------------------------------- ------


你必须为服务器表写一个特定的select语句

你要更新或添加行和插入/ update语句有

来满足服务器上表的约束条件。

然后 - 查看连接表只需写一个简单的

"选择t1。*来自tbl1 t1加入tbl2 t2 on t1.ID = t2.ID"


da.Fill(ds," tblB")


一旦掌握了ADO.Net,您就会看到它打破了经典ADO的大门



Rich


***通过开发人员指南 http:/ /www.developersdex.com ***


我不知道您可以使用记录集更新已连接的数据表,我

认为它只是在做桌子。


但是如果你想使用SQLDataAdapter更新数据表,那么

你需要的只是之前做的事情那个更新的地方


dim cmb = new SqlCommandBuilder(TheDataAdapter)


Cor


" endy_tj" < en ***** @ lycos.comschreef in bericht

news:62 ************************* ********* @ i36g2000 prf.googlegroups.com ...


在vb6中,我可以使用ADO的记录集从数据库中检索数据,对数据工作

,然后将修改发送回数据库。


我使用断开连接的记录集,并调用updatebatch将更新发送到

数据库。


在vb.net中,我使用datatable从数据库中检索数据并处理

数据。下一步,将更新发送到数据库,对我来说是一个两难的问题。


如果我使用dataadapter发送更新,那么我必须提供插入,

更新,手动删除命令。


如果我使用tableadapter,那么我必须限制自己使用匹配的

键入的数据表。非常有限,因为我通常在我的select语句(或sql子查询)中执行sql join

,在网格上显示数据,

让用户修改,然后保存更改到数据库。使用

tableadapter,在事务数据中显示查找数据不再容易。


另一种方法是使用存储过程,但后来我必须使用支持存储过程的
数据库。我也更喜欢保持

数据库哑,并将所有逻辑存储在一个地方,即程序。


还有其他方法吗?或者我应该咬紧牙关并构建我的

自己的命令生成器?


-

Endy

In vb6 I can use ADO''s recordset to retrieve data from database, work
on the data, then send the modifications back to the database.

I use disconnected recordset, and call updatebatch to send updates to
database.

In vb.net, I use datatable to retrieve data from database and work on
the data. The next step, sending the updates to database, is a dilemma
for me.

If I use dataadapter to send updates, then I have to provide insert,
update, delete commands manually.

If I use tableadapter, then I must limit myself to use the matching
strongly typed datatable. Very limiting because I usually do sql join
in my select statement (or sql subquery), display the data on a grid,
let user modify, then save the changes back to database. Using
tableadapter, showing lookup data in transaction data is no longer
easy.

Another way is to use stored procedure, but then I have to use
database that supports stored procedure. I also prefer to keep the
database dumb, and store all the logic in one place, the program.

Is there any other way? Or should I just bite the bullet and build my
own command generator?

--
Endy

解决方案

endy_tj wrote:

>
Is there any other way? Or should I just bite the bullet and build my
own command generator?

I don''t use a data adapter or a table adapter. I have 3 methods, one for insert,
update, and delete, that will take any table, and create and run the appropriate
commands. It takes a bit of work to set it up; once you have it, though, that
task is done for good.


The way VS.Net works (VB.Net/C# for this explanation) is that is sort of
creates an in memory database with the objects selected from the server
DB. If you have related tables on the server DB and want to view data
from these tables you would use a select statement as follows in a
dataAdapter:

''--these vars are global
dim da As SqlDataAdapter, ds As Dataset, conn as SqlConnection
---------------------------------------------
Private Sub Form1_Load(...) Handles....
da = New SqlDataAdapter
ds = New Dataset
da.SelectCommand = new SqlCommand
da.SelectComman.Connection = conn
da.InsertCommand = New sqlCommand
da.InsertCommand.Connection = conn
da.InsertCommand.Parameters.Add("@p1",...)
da.UpdateCommand = New SqlCommand
da.UpdateCommand.Connection = conn
da.UpdateCommand.Parameters.Add("@p1",...)
da.SelectCommand.CommandText = "Select * From tbl1"
da.Fill(ds, "tblA")
datagridview1.DataSource = ds.Tables("tblA")
...
End Sub

Private Sub datagridview1CellValue_Changed(...) Handles...
ds.Tables("tblA").Rows(e.RowIndex)(e.ColumnIndex) =
datagridview1.Rows(e.RowIndex).Cells(e.columnIndex ).Value

da.Update(ds,"tblA")
End Sub
-----------------------------------------------------

you have to write a specific select statement for the server table that
you want to update or add rows to and the insert/Update statements have
to meet the constraint conditions place on the tables on the server.
Then - to view joined tables just write a simple

"Select t1.* from tbl1 t1 Join tbl2 t2 on t1.ID = t2.ID"

da.Fill(ds, "tblB")

Once you get the hang of ADO.Net you will see that it blows the doors
off classic ADO.
Rich

*** Sent via Developersdex http://www.developersdex.com ***


I did not know that you could update joined datatables with the recordset, I
thought that it was only doing tables.

However if you want to update a datatable using a SQLDataAdapter then the
only thing you need is to do before that update somewhere

dim cmb = new SqlCommandBuilder(TheDataAdapter)

Cor

"endy_tj" <en*****@lycos.comschreef in bericht
news:62**********************************@i36g2000 prf.googlegroups.com...

In vb6 I can use ADO''s recordset to retrieve data from database, work
on the data, then send the modifications back to the database.

I use disconnected recordset, and call updatebatch to send updates to
database.

In vb.net, I use datatable to retrieve data from database and work on
the data. The next step, sending the updates to database, is a dilemma
for me.

If I use dataadapter to send updates, then I have to provide insert,
update, delete commands manually.

If I use tableadapter, then I must limit myself to use the matching
strongly typed datatable. Very limiting because I usually do sql join
in my select statement (or sql subquery), display the data on a grid,
let user modify, then save the changes back to database. Using
tableadapter, showing lookup data in transaction data is no longer
easy.

Another way is to use stored procedure, but then I have to use
database that supports stored procedure. I also prefer to keep the
database dumb, and store all the logic in one place, the program.

Is there any other way? Or should I just bite the bullet and build my
own command generator?

--
Endy


这篇关于vb6在vb.net中的记录集替换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆