The call to the stored procedure in SQLServer2000 under .NET.

xiaoxiao2021-03-06  47

First, create a stored procedure in SQL Server, divided into parameters and no parameters in call,

First brief introduction to the situation where there is no parameters:

Suppose the stored procedure is as follows: Create Proc SelectAll

AS

Select * from studentinf

Then the call of this sp is as follows:

Sqlcommand selectcmd = new sqlcommand ("selectall, conn);

// conn is SqlConnection

Selectcmd.commandtype = commandtype.storedProcedure;

If you need to add the result set to a DataAdapter, you can follow:

SqlDataAdapter Studa = New SqlDataAdapter ();

Studa.selectCommand = SELECTCMD;

If there is a parameter: CREATE PROC andSELECT

@Studentid varchar (10),

@Studentname varchar (10),

AS

Select * from studentinf where studentid = @studentid and studentname = @studentname

Then the parameter can be added as follows:

Selectcmd.Parameters.Add ("@ studentid", SqldbType.nvarchar, 10);

Selectcmd.Parameters.Add ("@ studentname", Sqldbtype.nvarchar, 10);

If there is only one parameter, you can assign this:

SQLParameters Onepara = selectcmd.Parameters.add ("@ studentid", SqldbType.nvarchar, 10);

Onepara.value = "a string"

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

New Post(0)