[FAQ] ASP extracts the value in the multi-selection list box and passes it to the stored procedure.

xiaoxiao2021-03-05  21

[Netizen asked] How do I extract

This is a list box that can be selected in the list box. Now the problem is: How can I achieve multiple values ​​in the list and get the result set, and query the submitted value with the SQL statement? Please give Help, thank you!

[Griefforyou Answer] After selecting multiple items, the submission will automatically separate data with a comma.

[Netizen asked] Thank you, version of the master, I can't transfer multiple selected result sets, and I want to do a SELECT query with the data value selected in the list, if you have selected it in the list. Multiple values, how to get this value and how to use it to do inquiry? Can you have an example? Hope! thank you all!

[Griefforyou Answer] <% IF Request.form ("Action") <> "" "" SELECT * home ",", ",", ",", ",", " , '") &") "response.write sqlend if%>

I chose 2, 3, the generated SQL is SELECT * from Table Where FieldName in ('2', '3')

[User asked] If you need a stored procedure, if you need a stored procedure, you have no problem when you select a project in the list, but there will be a problem with two or more: Microsoft OLE DB Provider for SQL Server error '80040e14' Pass the number of parameters 2, and pass the following parameters in the form of '@Name = value'. Once the '@Name = value' form is used, all subsequent parameters must be passed in the form of '@Name = value'. In the use of stored procedures Select * from table where @fieldname = ('"& replace (" SELECT "),", ",", "", ",", ",", ",", ",", ",", the reason is @fieldname can not assign multiple values ​​to the variables in the stored procedure once, only a single given. At this time, you may need to save multiple selected list values ​​as a variable or array? But how to achieve? Please help again Solution, okay?!

[GRIEFFORYOU AX] 1. Treatment of numeric fields a. Stored Procedure Create Procedure SP_TEST (@ID varchar (1000)) AS

Declare @sql nvarchar (2000)

Set @ SQL = N'SELECT * from Book Where ID in (' @ID ') '- Generate SQL Statement EXEC SP_EXECUTESQL @ SQLGOB.ASP Program <% DIM Connstrdim CN, CMD, RSDIM ID

If Request.form ("Action") <> "" THEN "acquires the query condition ID = Replace (" SELECT "),", ",", ","), is not plus single query. Connection string connStr = "provider = sqloledb.1; password = sa; persist security info = true; user id = sa; initial catalog = book; data source = (local)" Creating Connection object set cn = server.createObject "Adodb.connection") 'connection database cn.open connStr' connection Command object set cmd = server.createObject ("adoDb.command") 'Sets the connection cmd.activeConnection = CN' setting command type for the Command Object ("AdoDb.command") 'Setting the command type for storedurecmd.commandType = 4 'Specify stored procedure name cmd.commandtext = "sp_test" set stored procedure parameters cmd.parameters.Append cmd.createParameter ("@ ID", 200, 1, 1000) cmd ("@ ID") = ID' Direct Assignment to the stored procedure parameter 'Execute a storage process Return record set SET RS = cmd.executeWhile Not Rs.eof response.write RS ("BookName" & "& RS (" Writer ") &"
"RS .MOVENEXTWENDRS.CLOSESET RS = NothingSet cmd = NothingCn.Closset CN = Nothingend IF

%> 2. Characteristic field processing a. Store process Create Procedure SP_TEST2 (@writer varchar (1000)) AS

Declare @sql nvarchar (2000) set @ SQL = N'SELECT * from Book Where Writer in (' @Writer ') '- Generate SQL Statement EXEC SP_EXECUTESQL @ SQLGOB.ASP Program <% DIM Connstrdim CN, CMD, RSDIM Writer

If Request.form ("Action") <> "" The query condition Writer = Replace ("SELECT"), "", ",", ") 'is replaced when the user is submitted. 'Connection string connStr = "provider = sqloledb.1; password = sa; persist security info = true; user id = sa; initial catalog = book; data source = (local)" Creating Connection Object SET CN = Server.createObject ("AdoDb.Connection") 'Connecting Database CN.Open ConnStr' Connection Command Object SET CMD = Server.createObject ("AdoDb.command") 'Sets the connection cmd.activeConnection = CN' set command type for the Command object. CommandType = 4 'Specifies the stored procedure name cmd.commandtext = "sp_test2" set stored procedure parameters cmd.Parameters.Append cmd.createParameter ("@ writer", 200, 1, 1000) cmd ("@ Writer") = " "& Writer &" '"' plus a single quotem in both sides, and then assign a value to the stored procedure 'Execute a storage process Return record set set = cmd.executeWhile Not Rs.eof response.write RS (" BookName " ) & "" "" "W
" rs.movenextwend

Rs.closset RS = NothingSet cmd = NothingCn.Closset CN = Nothingend IF

转载请注明原文地址:https://www.9cbs.com/read-38802.html

New Post(0)