AS400 SQL query with Parameter

前端 未结 3 2034
花落未央
花落未央 2020-12-21 12:07

I am testing a simple query to get data from an AS400 database. I am not sure if the way I am using the SQL query is correct.

I get an error: \"The

3条回答
  •  无人及你
    2020-12-21 12:48

    Ok, I got the solution by playing around and trying different things.

    As I said before, I am used to OLEDB and ADO.Net so I am used to doing things like:

    Select FIELD1, FIELD2 From Mylibrary.MyTable WHERE FIELD1 = @Field1
    

    which work in Access and SQL Server but not in AS/400.

    I got the following to work:

    Select FIELD1, FIELD2 From Mylibrary.MyTable WHERE FIELD1 = ?
    
    cmd.ActiveConnection = connstr
    cmd.CommandType = 1'4   'Stored Procedures '1 Text
    cmd.CommandText = sql
    Set Param1 = cmd.CreateParameter("@Field1", 129, 1, 9, "myvalue")  ' 129 String
    cmd.Parameters.Append Param1
    Set rs = cmd.Execute()
    

    This is all VbScript. The trick was to add the question mark(?) in the sql statement.

提交回复
热议问题