SQL Reader VB示例 [英] SQL Reader VB Example

查看:100
本文介绍了SQL Reader VB示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道是否有人可以发布一个示例,说明如何使用VB从SQL读取记录流?

Just wondering if someone could post an example showing how to read a stream of records from SQL using VB?

我必须在  1.5中查找重复记录200万条记录。例如,如果有两个Paul Revere,我需要找到这两个记录并将它们放在Excel电子表格中。 (我在这里简化了这个过程)。我正在做什么
现在:

I have to look for duplicate records in 1.5 to 2 million records. For example, if there are two Paul Revere's I need to find those two records and put them in an Excel spreadsheet. (I've simplified the process here quite a bit). What I'm doing now:

1)运行SQL程序来获取和排序所需记录的子集。

1) Run SQL procedure to get and sort the subset of records needed.

2) SQl过程将记录子集放在SQL工作表中。

2) The SQl procedure puts the subset of records in a SQL work table.

3)在客户端(VB),我读取了10,000条记录的块和

3) On the client side (VB) I read in blocks of 10,000 records and

处理记录。我有两个IEnumerator类。一个类

process the records. I've got two IEnumerator classes. One class to

从SQL读取记录块并将调用者一条记录交给

read blocks of records from SQL and hand the caller one record at

一次。第二个IEnumerator通过从第一个IEnumerator一次读取一条记录来分组记录(使用IComparer)

a time. The 2nd IEnumerator groups records (using a IComparer)

4)VB代码获取一组重复记录和

4) The VB code gets one group of duplicate records and

执行额外处理:删除不需要的记录等。

performs additional processing: Removes unneeded records, etc.

5)如果两个或多个记录保留在组中,则输出

5) If two or more records remain in the group then output

电子表格中的记录。

 

我想做的是替换IEnumerator#1以使用Reactive。我希望

What I'd like to do is replace IEnumerator #1 to use Reactive. I'd like

读取新记录,而我正在处理VB中的记录。

to be reading new records while I'm processing records in VB.

 

感谢您提供工作样本。

Ed

 

推荐答案

嗨Ed,

SQL 服务器在获取行时不会被激活,尽管您可以使初始读取异步使用
BeginExecute * 方法。 例如:

SQL Server isn't reactive when fetching rows, although you can make the initial read asynchronous by using a BeginExecute* method.  For example:

http:// msdn .microsoft.com / zh-CN / library / 4kkwyh68.aspx

您可以使用 Observable.FromAsyncPattern 以单例可观察的方式执行命令序列; 即,它可能(但可能不会)在SQL服务器上异步启动查询,并在
结果集准备就绪时仅推送一个通知。 例如,您将获得 IObservable< SqlDataReader>
,一旦SQL Server准备好结果集,就会包含一个 SqlDataReader

You can use Observable.FromAsyncPattern to execute the command as a singleton observable sequence;  i.e., it may (but it might not) begin the query on SQL server asynchronously and push only a single notification when the result set is ready.  For example, you'll get an IObservable<SqlDataReader> that contains a single SqlDataReader once SQL Server is ready with the result set.

然后你可以使用你的第一个枚举器来拉通常记录。

Then you can use your 1st enumerator to pull records normally.

也可能需要将整个结果集转换为 IEnumerable<?> 
IObservable< ;?> &NBSP;对于前者,我会在C#中编写一个迭代器块。 我不确定VB中最好的解决方案是什么。 对于后者,我会使用
Observable.Create。

It also may be desirable to convert the entire result set into an IEnumerable<?> or IObservable<?>.  For the former, I'd write an iterator block in C#.  I'm not sure what the best solution is in VB.  For the latter, I'd use Observable.Create.

我会将工作项添加到 Rxx (一个Rx贡献项目)包含SQL Server命令的observable包装器。

I'll add a work item to Rxx (an Rx contribution project) to include observables wrappers for SQL Server commands.

工作项: http://rxx.codeplex.com/workitem/21557

- 戴夫


这篇关于SQL Reader VB示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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