Solved

run stored procedure from vb.net

Posted on 2016-08-15
4
30 Views
Last Modified: 2016-08-15
I would like to run the stored procedure but I dont need any data from it as its doing an update and some housekeeping.

how do i do that without having to create a reader etc.

normally i would do this:

   dtWords = New DataTable
        Dim connectionString As String = ConfigurationManager.ConnectionStrings("Dictionary").ConnectionString

        Using conn As New SqlConnection(connectionString)
            Using cmd As New SqlCommand(StrProcName, conn)
                cmd.CommandTimeout = 0
                cmd.CommandType = CommandType.StoredProcedure
                conn.Open()

                cmd.Parameters.AddWithValue("@Client", StrClient)

                If OpShortDescCars.Checked = True Or OpShortDescBikes.Checked = True Or OpShortDescLcv.Checked = True Or OpShortDescOthers.Checked = True Then
                    cmd.Parameters.AddWithValue("@VCategory", StrVehCat)

                ElseIf OpShortDescCarsLcvOthers.Checked = True Or OpShortDescBikesQuads.Checked = True Then
                    cmd.Parameters.AddWithValue("@VCatSuper", StrVehCat)

                ElseIf OpShortDescAll.Checked = True Then
                    ' no params
                End If

                Dim reader As SqlDataReader = cmd.ExecuteReader()
                dtWords.Load(reader)
            End Using
        End Using
        Return dtWords

Open in new window

0
Comment
Question by:PeterBaileyUk
  • 3
4 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 500 total points
Comment Utility
try use ExecuteScalar? like:

cmd.CommandTimeout = 0
                cmd.CommandType = CommandType.StoredProcedure
                conn.Open()

                '....

cmd.ExecuteScalar()

Open in new window

0
 

Author Comment

by:PeterBaileyUk
Comment Utility
Will this do the job
    Public Sub CreateAllStrs()

        Dim StrProcName As String
        StrProcName = "usp_CreateStrStringsPlusTidyup"

        Dim connectionString As String = ConfigurationManager.ConnectionStrings("Dictionary").ConnectionString

        Using conn As New SqlConnection(connectionString)
            Using cmd As New SqlCommand(StrProcName, conn)
                cmd.CommandTimeout = 0
                cmd.CommandType = CommandType.StoredProcedure
                conn.Open()
                cmd.ExecuteReader()
            End Using
        End Using

    End Sub

Open in new window

0
 

Author Comment

by:PeterBaileyUk
Comment Utility
so to this
    Public Sub CreateAllStrs()

        Dim StrProcName As String
        StrProcName = "usp_CreateStrStringsPlusTidyup"

        Dim connectionString As String = ConfigurationManager.ConnectionStrings("Dictionary").ConnectionString

        Using conn As New SqlConnection(connectionString)
            Using cmd As New SqlCommand(StrProcName, conn)
                cmd.CommandTimeout = 0
                cmd.CommandType = CommandType.StoredProcedure
                conn.Open()
                cmd.ExecuteScalar()
            End Using
        End Using

    End Sub

Open in new window

0
 

Author Closing Comment

by:PeterBaileyUk
Comment Utility
thank you
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now