Mmmm puedes crear una variable a nivel de tu clase o formulario donde estés ejecutando :
luego le pasas el valor a esta variable en tu procedimiento :
Código vb:
Ver originalDim cmd As New SqlCommand("doppingsort", cnn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection.Open()
cmd.Parameters.AddWithValue("@L", 1)
cmd.Parameters.AddWithValue("@U", 5)
ID_GENERAL = MaxSort() + 1
Using sdr As SqlDataReader = cmd.ExecuteReader()
While sdr.Read()
table.AddCell(sdr(0).ToString())
table.AddCell(sdr(1).ToString())
table.AddCell(sdr(2).ToString())
table.AddCell(sdr(3).ToString())
table.AddCell(sdr(4).ToString())
Insertar()
End While
sdr.Close()
y finalmente en tu insertar le pasas la variable :
Código vb:
Ver originalPublic Function Insertar() As Integer
Dim sql As String
sql = "INSERT INTO sorting" & _
"(id,sort_num,id_person, date, year,month) " & _
"VALUES " & _
"(@id,@SortNum,@Idperson, @DateSort, @YearSort,@MonthSort) "
Using cnn As New SqlConnection(cs)
Dim cmd As New SqlCommand(sql, cnn)
Dim NextID As Integer = MaxId() + 1
Dim A As Integer = A + 1
cmd.Parameters.AddWithValue("@id", NextID)
cmd.Parameters.AddWithValue("@SortNum", ID_GENERAL )
cmd.Parameters.AddWithValue("@Idperson", A)
cmd.Parameters.AddWithValue("@DateSort", Date.Now)
cmd.Parameters.AddWithValue("@YearSort", Date.Now.Year)
cmd.Parameters.AddWithValue("@MonthSort", Date.Now.Month)
cnn.Open()
Dim t As Integer = Convert.ToInt32(cmd.ExecuteScalar())
Return t
End Using
End Function
Eso? Claro si todo está dentro de una misma clase.