对 SQLDataSource 中的每条记录执行操作

发布于 2024-10-19 06:27:35 字数 370 浏览 6 评论 0原文

我最近提交了很多问题 - 但这是一个很棒的信息库。如您所见,我是一个 .NET 新手,因此如果我缺少基础知识或信息,请告诉我,我会尽力填补空白。

我使用 ASP.NET/VB.NET 通过 SQL 2005 创建这个。我有一个项目,我想从表中获取一组记录,然后通过 API 发送每条记录,获取结果并写回结果到一个表,然后移动到下一个。

最初,我的想法是创建一个 SQLDataSource 来获取所有记录,然后在按钮上执行操作以执行发送每条记录的操作。

有没有办法可以从 SQLDataSource 调用记录集并执行循环?我正在考虑类似于经典 ASP/VBScript 中的内容,您将打开一个记录集,执行一个操作,然后循环直到 RS 为 EoF。

感谢您的帮助!

I've submitted a bunch of questions as of late - but this has been a great repository of information. I'm a .NET nub, as you can see, so if I'm missing basics or information please let me know and I'll try and fill in the gaps.

I'm using ASP.NET/VB.NET to create this with SQL 2005. I have a project where I'd like to take a set of records from a table, then send each one through an API, get a result and writeback the result to a table, then move to the next.

Initially, my thought was create a SQLDataSource that grabs all the records, then perform the action on a button to do the action of sending through each record.

Is there a way I can call the recordset from SQLDataSource and perform a loop? I'm thinking something like in Classic ASP/VBScript where you would open a RecordSet, do an action, then Loop until the RS was EoF.

Thanks for the help!

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

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

发布评论

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

评论(1

诗化ㄋ丶相逢 2024-10-26 06:27:35

您可能希望将结果放入数据集中。获得结果后,您可以循环返回的行

Dim ds As Dataset = GetSomeDataFromSq

For Each dr As DataRow In ds.Tables(0).Rows
    Console.WriteLine (dr("ColName"))
Next

您也可以使用 sqlDataReader

    Using conn As sqlconnection = New sqlconnection("put conn info")
        Using MyCommand As SqlCommand = New SqlCommand("SELECT ProductName FROM products", conn)
            conn.Open()
            Using myDataREader As SqlDataReader = MyCommand.ExecuteReader
                While myDataREader.Read
                    Response.Write("Name: " & myDataREader.Item("ProductName"))
                End While
            End Using
        End Using
    End Using

You can may want to put your results in a dataset. After getting the results, you can loop through the returned rows

Dim ds As Dataset = GetSomeDataFromSq

For Each dr As DataRow In ds.Tables(0).Rows
    Console.WriteLine (dr("ColName"))
Next

You could also use a sqlDataReader

    Using conn As sqlconnection = New sqlconnection("put conn info")
        Using MyCommand As SqlCommand = New SqlCommand("SELECT ProductName FROM products", conn)
            conn.Open()
            Using myDataREader As SqlDataReader = MyCommand.ExecuteReader
                While myDataREader.Read
                    Response.Write("Name: " & myDataREader.Item("ProductName"))
                End While
            End Using
        End Using
    End Using
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文