December 16, 2017, 05:38:32 PM
News: IF YOU ARE A MEMBER FROM THE ORIGINAL SITE AND CAN'T LOGIN. POST IN THE FEEDBACK FORUM (AS GUEST) AND AN ADMIN WILL ASSIST YOU TO ACCESS THE SITE!
Pages: [1]   Go Down
Author Topic: ASP.Net (VB) - stored procedure not firing? **Resolved**  (Read 5899 times)
msimmons
Administrator
*

Stars: +3/-0
Offline Offline

Gender: Male
Posts: 8459



WWW
« on: December 07, 2012, 12:56:43 PM »

Ok, I've a bit of code that runs and feeds data from an xml file into a database table. In the process of doing that, I run a stored proc that will delete old data fed in on previous runs... but the data is not being deleted...

I know it is not the sproc itself, because I can run that via the query analyzer and records are deleted.

I know the code (posted below) is firing because I get "success" in my gErrorMsg that I am setting.

Is there something stupid I am not seeing, like I'm not executing the sproc, or something?  crash


Code:
   Private Function dropLSItems(ByVal fSellerId As Integer) As Boolean
        Dim sqlConn2 As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("constring").ToString())
        Dim cmd2 As SqlCommand = sqlConn2.CreateCommand
        cmd2.CommandType = CommandType.StoredProcedure

        cmd2.CommandText = "uspDeleteLsItems_BySellerId"
        cmd2.Parameters.AddWithValue("@SellerId", fSellerId)

        Using (sqlConn2)
            Try
                sqlConn2.Open()
                cmd2.ExecuteNonQuery()
                gErrorMsg = gErrorMsg & vbCrLf & "<br>dropLSItems sucess: [sellerid:" & gSellerId & "] " & vbCrLf & "<br>last sql:uspDeleteLsItems_BySellerId"
                Return True
            Catch ex As Exception
                gErrorMsg = gErrorMsg & vbCrLf & "<br>dropLSItems fail: [sellerid:" & gSellerId & "] " & ex.Message & vbCrLf & "<br>last sql:uspDeleteLsItems_BySellerId"
                HttpContext.Current.Response.Write("dropLSItems: " & ex.Message & "<br>")
                Return False
            End Try
        End Using

    End Function
« Last Edit: December 08, 2012, 08:18:15 AM by msimmons » Logged

                 ..... .....

Jason Reed
Administrator
*

Stars: +4/-0
Offline Offline

Gender: Male
Posts: 4440


Pure Evil Administrator


WWW
« Reply #1 on: December 07, 2012, 04:25:01 PM »

I'm pretty doubtful that this is the problem, but it looks like in your gErrorMsg line that you are using a variable that is not declared before. The gSellerId which probably has nothing to do with why the sproc is working or not.
Logged

-- signature --

msimmons
Administrator
*

Stars: +3/-0
Offline Offline

Gender: Male
Posts: 8459



WWW
« Reply #2 on: December 07, 2012, 04:26:45 PM »

those are globals (i preface them with g) so they are defined at the start of the class.

however! I need to change that to be the id that the function is passing in, just to be sure it is correct, you may have found it Grin (I've modified the code, but won't know till tomorrows run Another Tounge takes forever to debug like this)
« Last Edit: December 07, 2012, 04:29:45 PM by msimmons » Logged

                 ..... .....

msimmons
Administrator
*

Stars: +3/-0
Offline Offline

Gender: Male
Posts: 8459



WWW
« Reply #3 on: December 08, 2012, 08:13:22 AM »

That was it! doh It wasn't deleting anything because I was passing in the wrong Id  laugh1


thanks  happydance
Logged

                 ..... .....

Jason Reed
Administrator
*

Stars: +4/-0
Offline Offline

Gender: Male
Posts: 4440


Pure Evil Administrator


WWW
« Reply #4 on: December 08, 2012, 08:41:21 AM »

Thus another reason why Global Variables are bad juju.
Logged

-- signature --

msimmons
Administrator
*

Stars: +3/-0
Offline Offline

Gender: Male
Posts: 8459



WWW
« Reply #5 on: December 08, 2012, 08:47:03 AM »

yeah, vbscript taught me a lot of bad habits that .net is getting me out of. I LOVE block level variables now, so when I have to write vbscript, I put everything is sub routines. With that app, I have two id's for each "seller" one for my database, and one for a 3rd party database... I had mine (correct one) in the global, but theirs (wrong one) was being passed in.
Logged

                 ..... .....

Pages: [1]   Go Up
Print
 
Jump to: