ADODB CreateParameter方法中name参数的用途是什么?

时间:2021-06-18 01:50:21

So I am working on modifying an existing query in classic ASP. Classic ASP is fairly new to me, especially this ADODB Command stuff.

所以我正在修改经典ASP中的现有查询。经典的ASP对我来说相当新,特别是这个ADODB Command的东西。

As it says on Microsoft's Docs

正如它在微软的Docs上所说的那样

Name
Optional. A String value that contains the name of the Parameter object.

While the other stuff is also nothing I'm familiar with, those are questions for another day.

虽然其他东西也不是我熟悉的,但这些都是另一天的问题。

sql = "INSERT INTO Paintings (pieceName, artistName, description, galleryID) VALUES (?, ?, ?, ?)"  
set sqlCmd = Server.CreateObjects("ADODB.Command")
sqlCmd.Parameters.Append(sqlCmd.CreateParameter("@PieceName",adVarChar,adParamInput, 256, txtPieceName))  
sqlCmd.Parameters.Append(sqlCmd.CreateParameter("@ArtistName",adVarChar,adParamInput, 256, txtArtist))
sqlCmd.Parameters.Append(sqlCmd.CreateParameter("@Description",adVarChar,adParamInput, 5000, txtDescription))
sqlCmd.Parameters.Append(sqlCmd.CreateParameter("@Description",adInteger,adParamInput, 256, txtGalleryID))

ADODBCon.query(sql, sqlCmd)

Point is, the code is from their live branch. I can see that @Description doesn't match the SQL, so I can figure the command is either case insensitive or the name argument isn't related to the SQL at all.

重点是,代码来自他们的实时分支。我可以看到@Description与SQL不匹配,所以我可以认为该命令不区分大小写或者name参数根本不与SQL相关。

Second, @Description is used twice and still works, with two different types. I know it says optional, but if it does not relate to the SQL, and can exist by the same name with different types, is it just for readability?

其次,@ Description使用两次仍然有效,有两种不同的类型。我知道它是可选的,但如果它与SQL无关,并且可以使用不同类型的同名存在,那是否只是为了可读性?

I'm sorry if A String value that contains the name of the Parameter object completely explains its purpose and I'm just not getting it, but what is the purpose of the name argument?

我很抱歉,如果一个包含Parameter对象名称的String值完全解释了它的用途,我只是没有得到它,但是name参数的目的是什么?

1 个解决方案

#1


3  

The CreateParameter method is actually creating a Parameter object which the .Append method then adds to the ADODB.Command object's, sqlCmd in this case, Parameters collection. Since it is a collection, the name is optional as a collection item can be accessed by item index.

CreateParameter方法实际上是创建一个Parameter对象,然后.Append方法将该对象添加到ADODB.Command对象的sqlCmd(本例中为Parameters集合)。由于它是一个集合,因此名称是可选的,因为可以通过项索引访问集合项。

From the documentation on Parameter Name property:

从参数名称属性的文档:

For Parameter objects not yet appended to the Parameters collection, the Name property is read/write. For appended Parameter objects and all other objects, the Name property is read-only. Names do not have to be unique within a collection.

对于尚未附加到Parameters集合的Parameter对象,Name属性是读/写。对于附加的Parameter对象和所有其他对象,Name属性是只读的。名称在集合中不必是唯一的。

#1


3  

The CreateParameter method is actually creating a Parameter object which the .Append method then adds to the ADODB.Command object's, sqlCmd in this case, Parameters collection. Since it is a collection, the name is optional as a collection item can be accessed by item index.

CreateParameter方法实际上是创建一个Parameter对象,然后.Append方法将该对象添加到ADODB.Command对象的sqlCmd(本例中为Parameters集合)。由于它是一个集合,因此名称是可选的,因为可以通过项索引访问集合项。

From the documentation on Parameter Name property:

从参数名称属性的文档:

For Parameter objects not yet appended to the Parameters collection, the Name property is read/write. For appended Parameter objects and all other objects, the Name property is read-only. Names do not have to be unique within a collection.

对于尚未附加到Parameters集合的Parameter对象,Name属性是读/写。对于附加的Parameter对象和所有其他对象,Name属性是只读的。名称在集合中不必是唯一的。