开发者

Perform Action on Each Record from SQLDataSource

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 A开发者_运维知识库PI, 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!


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜