Subsequent scripts do not work when object is returned using SQL statement execution results to determine if statement conditions

Asked 1 years ago, Updated 1 years ago, 72 views

browsers:IE8
sqlserver:Microsoft SQL SERVER 2008

The following Javascript functions are called from the ASPX file and processed.
If the SELECT result for sqlServer is an [object] that does not exist in the table, the if statement else processing should work, but after else processing does not work and the function call ends.

I would like to know how to successfully determine the object in the SELECT result by conditional branching.
Or if the SELECT results are used incorrectly or if there is another way to judge, I would like to know the correct usage and means.

 function checkSMT_Z120(regClass, obj, z120, ovday, odlvprice){
    // Error avoidance ttry{~
    try{
        varobjADO=new ActiveXObject("ADODB.Connection");// Connect to DB using ADODB module
        var inputchk = obj.value // Get the entered part number as an argument
        varcompanyGrp=z120.value//Retrieves the z120 group entered as an argument
        varformVday=frmFormData.elements [ovday]; // Return old valid start date to form
        varformoDlvPrice=frmFormData.elements [odlvprice]; // Return old delivery price to form
        var formregClass=frmFormData.elements [regClass]; // Return registration classification to form

        // 1. Open the SQL Server DB using ADO
        objADO.Open("Driver={SQLServer};"+
                    "server=[ip]; database=[db name]; uid=[****]; pwd=[****];");

        // 2. Run SQL to see the registration status of the target table
        if(inputchk!=""){
            varret=objADO.Execute("select part number, amount, quantity, start date from Z120where customer G5='"+companyGrp
                                                                                                 + "'and part number='+inputchk
                                                                                                 + "'and End Date = '99991231'";
            if(ret("item number")!="[object]") {
                window.alert("true")
            } else{
                window.alert("false")
            }
        }
        
        // Close ADO
        objADO.Close();
        objADO=null;

    }
    catch(e){}

}

javascript sql-server

2022-09-30 21:22

2 Answers

Perhaps the value required for processing is not ret("item number") but ret("item number").Value

ret("part number") is of type ADODB.Field.This type is [object] when converted to a string, but it does not match the string "[object]".


2022-09-30 21:22

Execute results for the Connection object are returned by the Recordset object.
The object will be returned unless there is an error, so I think only the object will be returned.
Whether the record was successfully retrieved or not is determined by the EOF property of the Recordset object if you create it in an HTA, etc.I will return it in Boolean form, so it should work like if(ret.EOF){}.

Connection.Execute Method-MSDN

If you only want to get the first line, this code is fine, but if you want to do multiple lines, use MoveNext, EOF, etc. to loop.


2022-09-30 21:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.