Answers for "using variables and sql vb.net"

SQL
0

how to declare variables in vb.net and store variable data in sql server

Using connection As New SqlConnection("Data Source=(local)SQLEXPRESS;Integrated Security=True;Initial Catalog=tempdb;")
            connection.Open()

            Dim command As New SqlCommand(
                "UPDATE tblSAMP SET fieldSAMP1 = @fieldSAMP1, @fieldSAMP2 = fieldSAMP2 WHERE fieldSAMP3 = @fieldSAMP3",
                connection)
            ' assign input parameters
            command.Parameters.AddWithValue("@fieldSAMP1", 999)
            command.Parameters.AddWithValue("@fieldSAMP3", 9090909)

            ' output parameter was @decSamp
            Dim fieldSAMP2Parameter = command.Parameters.Add(
                New SqlParameter("@fieldSAMP2", SqlDbType.Int) With {.Direction = ParameterDirection.Output})

            ' if the query modified one row at least
            If command.ExecuteNonQuery() > 0 Then
                ' get the output parameter(s)
                Dim decSamp As Integer = CInt(fieldSAMP2Parameter.Value)
            End If
        End Using
Posted by: Guest on July-09-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language