How to Put in the 'Using cmd as New SqlCommand' Form


Author
Message
Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K
    Public Sub FillCountNonDRDOVR(ByVal nrod As Integer,
             ByVal cevt As String,
             ByVal ngo As Integer)
        Dim cmd = New SqlCommand("sp_CountBBNonDRDOVR")
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.Add("@rodeoid"SqlDbType.Int).Value = nrod
        cmd.Parameters.Add("@eventcd"SqlDbType.Char, 2).Value = cevt
        cmd.Parameters.Add("@goround"SqlDbType.Int).Value = ngo
        FillDataTable(cmd)
    End Sub

I have tried several different iterations of the above code but can not seem to get the correct syntax to put the above code in the following form:
Using cmd using as new SqlCommmand
...
End Using
TIA for any help.



Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Terry,
Here is my version of your code:

    Public Sub FillCountNonDRDOVR(ByVal nrod As Integer,
           ByVal cevt As String,
           ByVal ngo As Integer)
        Using cmd As New SqlCommand
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "dbo.sp_CountBBNonDRDOVR"

            cmd.Parameters.AddWithValue("@rodeoid", nrod).SqlDbType = SqlDbType.Int
            cmd.Parameters.AddWithValue("@eventcd", cevt).SqlDbType = SqlDbType.Char
            cmd.Parameters.AddWithValue("@goround", ngo).SqlDbType = SqlDbType.Int
            Me.FillDataTable(cmd)
        End Using
    End Sub


Keep in mind that for your Char parameter if you just using 2 characters length, so you may want to keep using the cmd.Parameters.Add() instead of cmd.Parameters.AddWithValue() so you can limit the Char to 2 characters.

Edhy Rijo

Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K
Great Thanks. I just was not using cmd.commandtext="sp_... since I thought that had to do only with Select Statements.
The Char parameter is set by my code so I don't think that should be a problem.
Again thank you so much.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search