Build a stored procedure in SQL Server, as shown below
Create Procedure [DBO]. [UserProcedureWithParameter]
@Username nvarchar (50)
AS
Select * from [user] where username like @username
Go
Call in ADO.NET
Private Void Page_Load (Object Sender, System.EventArgs E)
{
SqlConnection Con = New SqlConnection ();
Con.Connectionstring = "Workstation ID = overmind; packet size = 4096; user ID = sa; password = sa; data source = overmind; persist security info = false; initial catalog = wztj;
C.Open ();
Sqlcommand cm = new SQLCommand ("UserProcedureWithParameter", Con);
Cm.commandType = commandtype.storedProcedure;
SQLParameter Parameter1 = New Sqlparameter ("@ username", sqldbtype.nvarchar, 50);
Parameter1.Value = "%" "aa" "%";
CM.Parameters.Add (parameter1);
DataSet DS = New Dataset ();
SqlDataAdapter ad = New SqlDataAdapter (cm);
Ad.fill (DS, "User");
DataGrid1.datasource = DS;
DataGrid1.databind ();
// put user code to initialize the page
}
Hahahaha, it's just like this!