如何以编程方式从 .net 中使用通用列表中的数据填充 ado 记录集

发布于 2024-12-29 06:43:15 字数 1408 浏览 4 评论 0原文

背景: 包括在内,这样人们就不会问我到底为什么要这样做!

我已将一个古老的极其冗长且复杂的存储过程转换为 .NET 代码,因为需要进行大量更新,并且所有功能都在存储过程中,并且更新起来非常复杂。

该存储过程被网站内多个位置的经典 ASP 使用。

要求 我现在需要将这段新的 .NET 代码的结果作为记录集发送回经典 asp 我打算通过网络服务

到目前为止我所拥有的 来做到这一点 到目前为止,我已经发现我实际上可以像这样在.NET中创建一个记录集

 ADODB.Recordset rs = new Recordset();

,然后将其作为xml字符串返回给asp(我还没有测试过)

rs.Save(streamObj, PersistFormatEnum.adPersistXML);
// Get the string (XML) of the recordset
string outputXml = streamObj.ReadText(str.Size);
return outputXml;

然后在asp中我将使用这个我发现的函数这里在asp中将xml转换回记录集

Public Function RecordsetFromXMLString(sXML As String) As Recordset
    Dim oStream As ADODB.Stream
    Set oStream = New ADODB.Stream
    oStream.Open
    oStream.WriteText sXML   'Give the XML string to the ADO Stream
    oStream.Position = 0    'Set the stream position to the start
    Dim oRecordset As ADODB.Recordset
    Set oRecordset = New ADODB.Recordset
    oRecordset.Open oStream    'Open a recordset from the stream
    oStream.Close
    Set oStream = Nothing
    Set RecordsetFromXMLString = oRecordset  'Return the recordset
    Set oRecordset = Nothing
End Function

让我困惑的一点 在我的 .NET 中,我有一个通用列表,其中包含需要返回的所有数据。 我如何将其添加到我的记录集中?

Background:
Included so people don't ask Why on earth I am doing this!

I have converted an ancient extremely long winded and complex stored procedure to .NET code as a huge update was required and all functionality was in the stored procedure and was far to complicated to update.

This stored procedure was consumed by classic ASP in multiple places within the website.

Requirement
I now need to send the results of this new piece of .NET code back to classic asp as a recordset
I intend on doing this by webservice

What I have so Far
So far I have worked out that I can actually create a recordset in .NET like so

 ADODB.Recordset rs = new Recordset();

and then return it as an xml string to asp (I have not tested this yet)

rs.Save(streamObj, PersistFormatEnum.adPersistXML);
// Get the string (XML) of the recordset
string outputXml = streamObj.ReadText(str.Size);
return outputXml;

In the asp I will then use this function which I found here in the asp to convert the xml back to a recordset

Public Function RecordsetFromXMLString(sXML As String) As Recordset
    Dim oStream As ADODB.Stream
    Set oStream = New ADODB.Stream
    oStream.Open
    oStream.WriteText sXML   'Give the XML string to the ADO Stream
    oStream.Position = 0    'Set the stream position to the start
    Dim oRecordset As ADODB.Recordset
    Set oRecordset = New ADODB.Recordset
    oRecordset.Open oStream    'Open a recordset from the stream
    oStream.Close
    Set oStream = Nothing
    Set RecordsetFromXMLString = oRecordset  'Return the recordset
    Set oRecordset = Nothing
End Function

The bit that's puzzling me
In my .NET I have a generic list that contains all the data that needs to be returned.
How do I get this in my recordset?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绮烟 2025-01-05 06:43:15

您可以查看下面的链接,该链接解释了将 RecordSet 转换为通用列表并执行相反的操作。

http://app-code.net/wordpress/?p=417

转换列表到数据表
.NET - 将通用集合转换为 DataTable

您可以将 DataTable 转换为 RecordSet
http:// www.codeproject.com/Articles/10503/Simplest-code-to-convert-an-ADO-NET-DataTable-to-a

请检查这一点。

You can checkout below link which explains converting RecordSet to Generic list and do the reverse.

http://app-code.net/wordpress/?p=417

Convert LIst to Datatable
.NET - Convert Generic Collection to DataTable

You can Convert DataTable to RecordSet
http://www.codeproject.com/Articles/10503/Simplest-code-to-convert-an-ADO-NET-DataTable-to-a

Please check this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文