ASP.NET utilization stored procedure to achieve fuzzy query

xiaoxiao2021-03-05  27

First, the establishment procedure stored in MSSQL Northwind database table for the new employess stored procedure (Action fuzzy query by LastName): CREATE PROCEDURE Employess_Sel @lastname nvarchar (20) AS select lastname from Employees where lastname like '%' @lastname '%' Go Second, Form Design 1, New ASP.NET Web Application, named Websql, select Save Path and click OK. 2, add a Label, a TextBox, and a button button, then add a DataGrid control, right-click the DataGrid control selection property generator, then select the column in the open window, remove the automatic creation of the column , Add a binding column to the selected column to set the header as a lastname, set the data field to lastname. Click OK. Third, create an intermediate data layer right-click a solution, select New-Project-Class Library, Name to Clasql, select Save Path and click OK. Add the following code to the open class library: imports system.data.sqlclient public class class1 Dim Scon as new SqlConnection ("Server = localhost; database = northwind; uid = sa; pwd = 123") 'Create a query process public Function Emp_Sel (ByVal lastname As String) As DataSet scon.Open () scon.Close () 'command object definitions, and the use of stored procedures Dim scom As New SqlCommand scom.CommandType = CommandType.StoredProcedure scom.CommandText = "Employess_Sel" scom .Connection = SCON 'Defines a data adapter and sets the parameter DIM SDA AS New SqlDataAdapter ("@ lastname", sqldbtype.nvarchar) .Value = lastname' Defines a dataset object, and Fill Data Set DIM DS AS AS AS AS NEW DATASET TRY SDA.FILL (DS) CATCH EX AS End Class 4 Right-click on the "Reference" of the project, select Add reference, then select the item, add the CLASQL item to the selected component box, and then click OK.

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

New Post(0)