StrataFrame Forum

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

http://forum.strataframe.net/Topic29157.aspx

By Terry Bottorff - 12/3/2010

    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.


By Edhy Rijo - 12/3/2010

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.
By Terry Bottorff - 12/3/2010

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.