Solved

Stored Procedure when called from VB Subroutine is not working

Posted on 2012-04-06
8
345 Views
Last Modified: 2012-04-06
I have a stored procedure that deleted records from a table based on billdate field.  When I execute the stored procedure, it works fine.  However if I call it from a VB Subroutine, no rows are deleted.  I can't see anything wrong.  Can someone help?  (See attached files)

ALTER-PROCEDURE-dbo.doc

Sub-DelMonthlyHospPricingArchive.doc
0
Comment
Question by:kshumway
  • 4
  • 3
8 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 37817248
Try it as:
Sub DelMonthlyHospPricingArchive(ByVal dBillDate As Date)
        Dim cmdHP As New SqlCommand
        Try
            conn.Open()
            cmdHP.Connection = conn
            cmdHP.CommandType = CommandType.StoredProcedure
            cmdHP.Parameters.AddWithValue("@BillDate", dBilldate.ToString("yyyy-MM-dd"))
            cmdHP.CommandText = "DeleteHospPricingSQLArchive"
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            conn.Close()
        End Try
    End Sub

Open in new window


MSDN: http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx
0
 
LVL 18

Accepted Solution

by:
lludden earned 500 total points
ID: 37817293
You never call an execute method.

Sub DelMonthlyHospPricingArchive(ByVal dBillDate As Date)
        Dim cmdHP As New SqlCommand
        Try
            conn.Open()
            cmdHP.Connection = conn
            cmdHP.CommandType = CommandType.StoredProcedure
            cmdHP.Parameters.AddWithValue("@BillDate", dBilldate.ToString("yyyy-MM-dd"))
            cmdHP.CommandText = "DeleteHospPricingSQLArchive"
            cmdHP.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            conn.Close()
        End Try
    End Sub
0
 

Author Comment

by:kshumway
ID: 37817314
I execute the stored procedure in SQL Server.
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 59

Expert Comment

by:Kevin Cross
ID: 37817326
Good catch, @lludden! You have to execute the SqlCommand at some point, so if your code truly has that missing then try adding that first. If it doesn't work from there, my thought was that the date conversion was causing an issue (i.e., converting incorrectly and so not finding any records to delete). If that is the case, then the fix is to use ToString() to format the date as 'yyyy-MM-dd' or '2012-04-06', which SQL Server should understand as a date properly.
0
 

Author Comment

by:kshumway
ID: 37817333
OK - I just tried it and it still did not delete the records.  There are 4300 records - would that make a difference?
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 37817347
How are you calling the sub within VB?
0
 

Author Comment

by:kshumway
ID: 37817374
Oh - now I know what you mean - I knew something was missing but just couldn't see it:

 cmdHP.ExecuteNonQuery

Yes that was it.  However I could not do the date conversion without an error.  It worked the way I originally had it - with the exeute line, of course.

THANK YOU SO MUCH!  I have been looking at this forever and could not see what was wrong
0
 

Author Closing Comment

by:kshumway
ID: 37817377
Thank you again...
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

777 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