Flagging a Random Record
I am using the following select statement to randomly select a single row.
SELECT TOP 1 * FROM [TBL_Example] ORDER BY NEWID
What I need to do is flag this record so it won't be randomly selected the next time I run the above query. I know I need to add a where clause to the above statement. How do I insert a value into the bit data type I am using in that where clause when the record is being randomly selected.
I am using ASP.NET 2.0 and Visual Basic. I think I might need a statement like this in my code behind:
Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEv entArgs) Handles SqlDataSource1.Selecting
SqlDataSource1.UpdateParameters("Flag").DefaultVal ue = "True"
End Sub
And here is what I am working with as a datasource
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ MYCONNECTIONSTRING %>"
SelectCommand="SELECT TOP 1 * FROM [TBL_Example] ORDER BY NEWID()"
updatecommand="UPDATE [TBL_Example] SET [Flag] = @Flag">
<UpdateParameters>
<asp:Parameter Name="Flag" Type="boolean" />
</UpdateParameters>
</asp:SqlDataSource>
|