none
I am trying to execute a simple function with a button click event, but Ive tried many variations and can't make it work. RRS feed

  • Question

  • I'm using VS 2010 and SQLServer 2008 R1 to get a result from SQLServer into my ASPX page. The Function is returning a value of 0 which is incorrect, it should be 2. I would appreciate any help you care to provide.  ............Phil Hoop

    The Calling event is this Button Click event:

    '***********************************************************************************************

    Private SubbtnContinueImportInst_Click(sender AsObject, e AsSystem.EventArgs) HandlesbtnContinueImportInst.Click

    DimmiCountDups AsInt32

    iCountDups = CountInstlDups()

    Me.LabelDups.Visible = True

    Me.LabelDups.Text = iCountDups.ToString

    EndSub

    '********************************************************************************************

    The Function called is:

    '************************************************************************************************

    PublicFunctionCountInstlDups() AsInt32

    DimDupcount AsInt32

    DimstrImportQuery AsString

    strImportQuery = "Select Count (ImportInstitutionsID) "

    strImportQuery = strImportQuery & "FROM tmpImportInstutions"

    Me.LabelError.Text = "Testing InstDups"& strImportQuery

    DimImportconnstring AsString= ConfigurationManager.ConnectionString.("ApplicationServices").ConnectionString

    UsingImportconn AsNewSqlConnection(Importconnstring)

    DimImportcmd AsNewSqlCommand(strImportQuery, Importconn)

    Try

     Importconn.Open()

     Dupcount = Convert.ToInt32(Importcmd.ExecuteScalar()) 

    Catchex AsException

    EndTry

    EndUsing

    ReturnDupcount

    EndFunction

    '*************************************************************************************************

           

           

           

       

     


      


           

    Me.LabelDups.Text = iCountDups.ToString

       

    EndSub


    Phil Hoop

    Sunday, March 16, 2014 11:01 PM

All replies

  • Hello Phil Hoop,

    I am trying to help you with this issue. I made a demo which is similar with yours, however, it worked fine.

    Does it throw any error message? If not, could you debug this project? If you can, please add a breakpoint, and then press F10 to debug the program step by step to check the value of the variable:

    Dupcount.

    And please also check the executed TSQL, have a try to run it in database directly and check the result.

    If this does not help you, you can upload your project and table schema to skydrive:

    https://skydrive.live.com/

    ‎Regards.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 17, 2014 4:32 AM
    Moderator