Execute the stored procedure with the simplest and effective code in C # and return data

xiaoxiao2021-03-06  16

The stored procedure p_sys_login is defined as follows:

Create Procedure P_sys_login

@arguserid varchar (20), - Username

@argpassword varchar (20), - password

@ArgResult varchar (50) Output - Login Results

AS

/ *

...

* /

The following demonstrates how to perform this stored procedure with the simplest and effective code in C #:

///

/// User login verification

///

/// Username

/// Password

Public void login (String Userid, String Password)

{

// Database connection string is stored in web.config

String cnnstring = configurationSettings.appsettings ["connectionstring"];

SqlConnection CNN = New SQLCONNECTION (CNNString);

//

String SQL = String.Format ("EXEC P_SYS_LOGIN '{0}', '{1}', @Result Output",

UserID, Password);

SQLCOMMAND CMD = New SQLCOMMAND (SQL, CNN);

// Establish and add the parameters corresponding to "@Result output"

Sqlparameter paramresult = new sqlparameter ("@ result", sqldbtype.varchar, 50);

ParamResult.direction = parameterdirection.output;

Cmd.Parameters.Add (paramresult);

CNN.Open ();

cmd.executenonquery ();

CNN.Close ();

// Get the result of the stored procedure returned

String result = paramresult.value.tostring ();

// ... ...

}

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

New Post(0)