Solved

run stored procedure from vb.net

Posted on 2016-08-15
4
41 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
ID: 41757393
try use ExecuteScalar? like:

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

                '....

cmd.ExecuteScalar()

Open in new window

0
 

Author Comment

by:PeterBaileyUk
ID: 41757408
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
ID: 41757409
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
ID: 41757420
thank you
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need to update TableA to TableB 6 35
Variable Event ? 3 23
Get the selected ValueMember of Combobox 5 23
conditional join based on column 4 12
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ā€¦
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

861 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

22 Experts available now in Live!

Get 1:1 Help Now