Link to home
Start Free TrialLog in
Avatar of rcowen00
rcowen00Flag for United States of America

asked on

Stored Procedure not triggering

I have a button that should be firing the code below but it isn't doing anything.  No errors, nothing.  What am I doing wrong.  Thanks
Protected Sub btnSaveCompEvalProperty_Click(sender As Object, e As EventArgs) Handles btnSaveCompEvalProperty.Click
        UpdateVendorPropertySection()
    End Sub

    Private Sub UpdateVendorPropertySection()

        Dim cnn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("myprovalConnectionString").ConnectionString)
        Try
            Dim cmd As New System.Data.SqlClient.SqlCommand
            cmd.Connection = cnn
            cmd.CommandType = Data.CommandType.StoredProcedure
            cmd.CommandText = "dbo.CompEvalPropertyUpdate"
            cmd.Parameters.Add("@Listed12Months", Data.SqlDbType.VarChar).Value = txtListed12Months.Text
            cmd.Parameters.Add("@Sold12Months", Data.SqlDbType.VarChar).Value = txtSold12Months.Text
            Dim iUserId As New Guid(Membership.GetUser(My.User.Name).ProviderUserKey.ToString())
            cmd.Parameters.Add("@UserKey", Data.SqlDbType.VarChar).Value = iUserId.ToString
            cnn.Open()
            cmd.ExecuteScalar()
           
        Finally
            cnn.Close()
        End Try
    End Sub

Open in new window

Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

How do you know there is no error?

Try adding a

Catch ex as exception
       msgbox ex.tostring()
Avatar of rcowen00

ASKER

Still nothing, did I put it in the correct location?
Protected Sub btnSaveCompEvalProperty_Click(sender As Object, e As EventArgs) Handles btnSaveCompEvalProperty.Click
        UpdateVendorPropertySection()
    End Sub

    Private Sub UpdateVendorPropertySection()

        Dim cnn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("myprovalConnectionString").ConnectionString)
        Try
            Dim cmd As New System.Data.SqlClient.SqlCommand
            cmd.Connection = cnn
            cmd.CommandType = Data.CommandType.StoredProcedure
            cmd.CommandText = "dbo.CompEvalPropertyUpdate"
            cmd.Parameters.Add("@Listed12Months", Data.SqlDbType.VarChar).Value = txtListed12Months.Text
            cmd.Parameters.Add("@Sold12Months", Data.SqlDbType.VarChar).Value = txtSold12Months.Text
            Dim iUserId As New Guid(Membership.GetUser(My.User.Name).ProviderUserKey.ToString())
            cmd.Parameters.Add("@UserKey", Data.SqlDbType.VarChar).Value = iUserId.ToString
            cnn.Open()
            cmd.ExecuteScalar()
        Catch ex As Exception
            MsgBox(ex.ToString())
        Finally
            cnn.Close()

        End Try
    End Sub

Open in new window

Yes. So there is no error? Change

cmd.ExecuteScalar()

to

cmd.ExecuteNonQuery()
Still nothing
Protected Sub btnSaveCompEvalProperty_Click(sender As Object, e As EventArgs) Handles btnSaveCompEvalProperty.Click
        UpdateVendorPropertySection()
    End Sub

    Private Sub UpdateVendorPropertySection()

        Dim cnn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("myprovalConnectionString").ConnectionString)
        Try
            Dim cmd As New System.Data.SqlClient.SqlCommand
            cmd.Connection = cnn
            cmd.CommandType = Data.CommandType.StoredProcedure
            cmd.CommandText = "dbo.CompEvalPropertyUpdate"
            cmd.Parameters.Add("@Listed12Months", Data.SqlDbType.VarChar).Value = txtListed12Months.Text
            cmd.Parameters.Add("@Sold12Months", Data.SqlDbType.VarChar).Value = txtSold12Months.Text
            Dim iUserId As New Guid(Membership.GetUser(My.User.Name).ProviderUserKey.ToString())
            cmd.Parameters.Add("@UserKey", Data.SqlDbType.VarChar).Value = iUserId.ToString
            cnn.Open()
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox(ex.ToString())
        Finally
            cnn.Close()

        End Try
    End Sub

Open in new window

CodeCruiser,

Could the problem be the form tag?  I

 <form id="Form1" runat="server" action="#" onsubmit="showLocation(); return false;">
May be. Did you put a break point in code to see if its executing. Why do you have in form?
That is what is required to calculate distance between two properties using google maps.  I also found that I did not in the page load, but I thought I was triggering it from the Save button, not from postback.
Ok, so I am getting closer since the field is being zero'd out on open.  Which means (I believe) I am calling it from the wrong place.  Any suggestions?  Thank you.
Public Class CompEvalProperty
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim OrdersProductKey As String
        If (Request.QueryString("OrderProductKey") <> Nothing) Then
            OrdersProductKey = Request.QueryString("OrderProductKey")

            If Not IsPostBack Then
                LoadVendorPropertySection(Convert.ToString(Request.QueryString("OrderProductKey")))
            End If
            UpdateVendorPropertySection()
        End If
    End Sub

    Private Sub LoadVendorPropertySection(ByVal OrdersProductKey As String)
        Dim VendorId As String
        VendorId = Request.QueryString("VendorId")

        Dim cnn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("myprovalConnectionString").ConnectionString)
        Try
            Dim cmd As New System.Data.SqlClient.SqlCommand
            cmd.Connection = cnn
            cmd.CommandType = Data.CommandType.StoredProcedure
            cmd.CommandText = "dbo.GetOrdersProductByOrdersProductKey"
            cmd.Parameters.Add("@OrdersProductKey", Data.SqlDbType.VarChar).Value = OrdersProductKey
            cmd.Parameters.Add("@VendorId", Data.SqlDbType.VarChar).Value = VendorId
            Dim iUserId As New Guid(Membership.GetUser(My.User.Name).ProviderUserKey.ToString())
            cnn.Open()
            Dim dr As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader
            dr.Read()
            If dr.HasRows Then
                If Not IsDBNull(dr("LoanNumber")) Then txtLoanNumber.Text = dr("LoanNumber")
                If Not IsDBNull(dr("ReportEnteredDate")) Then txtDateEntered.Text = dr("ReportEnteredDate")
                If Not IsDBNull(dr("SubjectParcelNumber")) Then txtParcelNumber.Text = dr("SubjectParcelNumber")
                txtOwnerName.Text = dr("OwnerName")
                txtAddr1.Text = dr("PropAddr1")
                txtAddr2.Text = dr("PropAddr2")
                txtCity.Text = dr("PropCity")
                txtState.Text = dr("PropState")
                txtZip.Text = dr("PropZip")
                txtVendorCompanyName.Text = dr("VendorCompanyName")
                txtVendorName.Text = dr("VendorName")
                txtVendorPhone.Text = dr("VendorBusPhone")
                txtVendorFax.Text = dr("VendorFax")
                txtVendorEmail.Text = dr("VendorEmail")
                txtExperienceYear.Text = dr("YrsExp")
                address1.Text = dr("VendorAddrDistance")
                address2.Text = dr("SubjectAddrDistance")
                If Not IsDBNull(dr("BrokerSoldNumber")) Then txtSold12Months.Text = dr("BrokerSoldNumber")
                If Not IsDBNull(dr("BrokerListedNumber")) Then txtListed12Months.Text = dr("BrokerListedNumber")
            End If
        Finally
            cnn.Close()
        End Try
    End Sub

    Protected Sub btnInsertBrokerDistance_Click(sender As Object, e As EventArgs) Handles btnInsertBrokerDistance.Click
        BrokerDistCalcInsert()
    End Sub
    Private Sub BrokerDistCalcInsert()
        Dim cnn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("myprovalConnectionString").ConnectionString)
        Try
            Dim cmd As New System.Data.SqlClient.SqlCommand
            cmd.Connection = cnn
            cmd.CommandType = Data.CommandType.StoredProcedure
            cmd.CommandText = "dbo.BrokerDistCalcInsert"
            txtBrokerDistCalc.Text = hidBrokerDistCalc.Value
            cmd.Parameters.Add("@BrokerDistCalc", Data.SqlDbType.VarChar).Value = txtBrokerDistCalc.ToString
            cmd.Parameters.Add("@OrdersProductKey" = Request.QueryString("OrderProductKey"))
            Dim iUserId As New Guid(Membership.GetUser(My.User.Name).ProviderUserKey.ToString())
            cmd.Parameters.Add("@UserKey", Data.SqlDbType.VarChar).Value = iUserId.ToString
            cnn.Open()
            Dim dr As Data.SqlClient.SqlDataReader = cmd.ExecuteReader
            dr.Read()
        Finally
            cnn.Close()

        End Try
    End Sub

    Protected Sub btnCloseBrokerDistance_Click(sender As Object, e As EventArgs) Handles btnCloseBrokerDistance.Click
        pnlCalcBrokerDistance.Visible = False
    End Sub

Open in new window

I still can't figure out why the SP is not firing.  Any help is appreciated.  Thank you.
Public Class CompEvalProperty
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim OrdersProductKey As String
        If (Request.QueryString("OrderProductKey") <> Nothing) Then
            OrdersProductKey = Request.QueryString("OrderProductKey")
            
            If Not IsPostBack Then
                LoadVendorPropertySection(Convert.ToString(Request.QueryString("OrderProductKey")))

            End If

        End If
    End Sub

    Private Sub LoadVendorPropertySection(ByVal OrdersProductKey As String)
        Dim VendorId As String
        VendorId = Request.QueryString("VendorId")

        Dim cnn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("myprovalConnectionString").ConnectionString)
        Try
            Dim cmd As New System.Data.SqlClient.SqlCommand
            cmd.Connection = cnn
            cmd.CommandType = Data.CommandType.StoredProcedure
            cmd.CommandText = "dbo.GetOrdersProductByOrdersProductKey"
            cmd.Parameters.Add("@OrdersProductKey", Data.SqlDbType.VarChar).Value = OrdersProductKey
            cmd.Parameters.Add("@VendorId", Data.SqlDbType.VarChar).Value = VendorId
            Dim iUserId As New Guid(Membership.GetUser(My.User.Name).ProviderUserKey.ToString())
            cnn.Open()
            Dim dr As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader
            dr.Read()
            If dr.HasRows Then
                If Not IsDBNull(dr("LoanNumber")) Then txtLoanNumber.Text = dr("LoanNumber")
                If Not IsDBNull(dr("ReportEnteredDate")) Then txtDateEntered.Text = dr("ReportEnteredDate")
                If Not IsDBNull(dr("SubjectParcelNumber")) Then txtParcelNumber.Text = dr("SubjectParcelNumber")
                txtOwnerName.Text = dr("OwnerName")
                txtAddr1.Text = dr("PropAddr1")
                txtAddr2.Text = dr("PropAddr2")
                txtCity.Text = dr("PropCity")
                txtState.Text = dr("PropState")
                txtZip.Text = dr("PropZip")
                txtVendorCompanyName.Text = dr("VendorCompanyName")
                txtVendorName.Text = dr("VendorName")
                txtVendorPhone.Text = dr("VendorBusPhone")
                txtVendorFax.Text = dr("VendorFax")
                txtVendorEmail.Text = dr("VendorEmail")
                txtExperienceYear.Text = dr("YrsExp")
                address1.Text = dr("VendorAddrDistance")
                address2.Text = dr("SubjectAddrDistance")
                If Not IsDBNull(dr("BrokerSoldNumber")) Then txtSold12Months.Text = dr("BrokerSoldNumber")
                If Not IsDBNull(dr("BrokerListedNumber")) Then txtListed12Months.Text = dr("BrokerListedNumber")
            End If
        Finally
            cnn.Close()
        End Try
    End Sub

    Protected Sub btnInsertBrokerDistance_Click(sender As Object, e As EventArgs) Handles btnInsertBrokerDistance.Click

    End Sub
    Private Sub BrokerDistCalcInsert()
        Dim cnn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("myprovalConnectionString").ConnectionString)
        Try
            Dim cmd As New System.Data.SqlClient.SqlCommand
            cmd.Connection = cnn
            cmd.CommandType = Data.CommandType.StoredProcedure
            cmd.CommandText = "dbo.BrokerDistCalcInsert"
            txtBrokerDistCalc.Text = hidBrokerDistCalc.Value
            cmd.Parameters.Add("@BrokerDistCalc", Data.SqlDbType.VarChar).Value = txtBrokerDistCalc.ToString
            cmd.Parameters.Add("@OrdersProductKey" = Request.QueryString("OrderProductKey"))
            Dim iUserId As New Guid(Membership.GetUser(My.User.Name).ProviderUserKey.ToString())
            cmd.Parameters.Add("@UserKey", Data.SqlDbType.VarChar).Value = iUserId.ToString
            cnn.Open()
            Dim dr As Data.SqlClient.SqlDataReader = cmd.ExecuteReader
            dr.Read()
        Finally
            cnn.Close()

        End Try
    End Sub

    Protected Sub btnCloseBrokerDistance_Click(sender As Object, e As EventArgs) Handles btnCloseBrokerDistance.Click
        pnlCalcBrokerDistance.Visible = False
    End Sub

   

    Private Sub UpdateVendorPropertySection()

        Dim cnn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("myprovalConnectionString").ConnectionString)
        Try
            Dim cmd As New System.Data.SqlClient.SqlCommand
            cmd.Connection = cnn
            cmd.CommandType = Data.CommandType.StoredProcedure
            cmd.CommandText = "dbo.CompEvalPropertyUpdate"
            cmd.Parameters.Add("@OrdersProductKey", Data.SqlDbType.Int).Value = Request.QueryString("OrderProductKey")
            cmd.Parameters.Add("@Listed12Months", Data.SqlDbType.VarChar).Value = txtListed12Months.Text
            cmd.Parameters.Add("@Sold12Months", Data.SqlDbType.VarChar).Value = txtSold12Months.Text
            Dim iUserId As New Guid(Membership.GetUser(My.User.Name).ProviderUserKey.ToString())
            cmd.Parameters.Add("@UserId", Data.SqlDbType.VarChar).Value = iUserId.ToString
            cnn.Open()
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox(ex.ToString())
            Dim sRedirect As String = "GeneralMarketConditions.aspx?OrdersProduct=1&VendorId=cdd7f9d3-2ee6-489c-bd92-ad0b3735c7da"
            Response.Redirect(sRedirect)
        Finally
            cnn.Close()

        End Try
    End Sub

    Protected Sub btnSaveCompEvalProperty_Click(sender As Object, e As EventArgs) Handles btnSaveCompEvalProperty.Click
        UpdateVendorPropertySection()

    End Sub
End Class

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, can you clarify?  Thank you.
The form tag that you showed in http:#37299812 that could be a problem.
try removing  "return false;" from onsubmit attribute
dejaanbu- that did not change anything

codecruiser- If I remove the onsubmit entirely, it works.  But now the javascript to calculate the distance is not working.  How do I initiate the javascript when the user clicks?

  <asp:Button ID="btnCalcBrokerDistance" runat="server" Text="Calculate Broker Distance" />
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial