----vb code
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim sqlString As String = "sp_getOrbitCounter"
dsOrbitCounter.SelectCommand = sqlString
dsOrbitCounter.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
dsOrbitCounter.SelectParameters.Add("@CounterNum", "Int32", "12")
Dim dbReader As SqlDataReader = dsOrbitCounter.Select(DataSourceSelectArguments.Empty)
While dbReader.Read()
lblCH1RMANumber.Text = dbReader("objectid").ToString
End While
End Sub
---asp
<asp:SqlDataSource ID="dsOrbitCounter" runat="server"
ConnectionString="<%$ ConnectionStrings:MWConnection %>"
datasourcemode="DataReader" >
</asp:SqlDataSource>
<asp:Button ID="btnSubmit" runat="server" Text="Generate" />
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
dsOrbitCounter.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
dsOrbitCounter.SelectCommand = "sp_getOrbitCounter"
dsOrbitCounter.SelectParameters.Add("@CounterNum", TypeCode.Int32, "12")
dsOrbitCounter.SelectParameters(0).Direction = Data.ParameterDirection.Input
dsOrbitCounter.SelectParameters.Add(New Parameter("Return value"))
dsOrbitCounter.SelectParameters(1).Direction = Data.ParameterDirection.ReturnValue
lblCH1RMANumber.Text =
End Sub
CREATE PROCEDURE sp_getOrbitCounter (@@CounterNum int) AS
begin
declare @@Current int,
@CurrentCounter int
--Get Current Value
select @@current = currentcounter from midware..OrbitCounter where objectid = @@CounterNum
--Increment Value
update midware..orbitcounter set currentcounter = (@@Current + 1) where objectid = @@CounterNum
--Return Incremented Value
select @CurrentCounter = currentcounter from midware..OrbitCounter where objectid = @@CounterNum
return @CurrentCounter
end
GO
Dim connString As String = ConfigurationManager.ConnectionStrings("atsapp1").ToString
Dim myConnection As New SqlConnection(connString)
myConnection.Open()
Dim myCommand As New SqlCommand("sp_getOrbitCounter", myConnection)
myCommand.CommandType = CommandType.StoredProcedure
'Create a SqlParameter object to hold the output parameter value
Dim incrementParam As New SqlParameter("@CurrentCounter", SqlDbType.Int)
'IMPORTANT - must set Direction as Output
incrementParam.Direction = ParameterDirection.ReturnValue
'Finally, add the parameter to the Command's Parameters collection
myCommand.Parameters.Add(incrementParam)
'Call the sproc...
Dim reader As SqlDataReader = myCommand.ExecuteReader()
'Now you can grab the output parameter's value...
Dim CH1RMANumber As Int32 = incrementParam.Value
lblCH1RMANumber.Text = CH1RMANumber.ToString