Call the stored process in .NET

zhaozj2021-02-16  102

Today, I tried to get data with the stored procedure. The summary method is as follows:

1. SqlCommand and DataSet: SqlConnection conn = new SqlConnection ( "server = (local); uid =; password =; database ="); SqlCommand cmd = new SqlCommand ( "StoreProcedure", connn); cmd.CommandType = CommandType. STOREPROCEDURE;

Sqldataadapter dscommand = new sqldataadapter (cmd); Dataset DS = New Dataset (); DSCommand.Fill (DS);

2. SqlCommand and SqlDataAdapter without parameters: Sqlconnection conn = new SqlConnection ( "server = (local); uid =; password =; database ="); SqlCommand cmd = new SqlCommand ( "StoreProcedure", conn); cmd.CommandType = CommandType.StoreProcedure; SqlDataReader Dr = cmd.executeReader () while (Dr.Read ()) {response.write (Dr.Item ["Field"]);} with input parameters: sqlConnection conn = new SqlConnection ("Server = (local); uid =; password =; database = "); SqlCommand cmd = new SqlCommand (" StoreProcedure ", conn); cmd.CommandType = CommandType.StoreProcedure; param = command.Parameters.Add (" @ inputText ", SqlDbType .Int; param.value = inputValue; SqlDataReader DR = cmd.executeReader () while (Dr.Read ()) {} conn.close () with output parameters: sqlConnection conn = new SqlConnection ("Server = (" server = (loc); uid =; password =; database = "); SqlCommand cmd = new SqlCommand (" StoreProcedure ", conn); cmd.CommandType = CommandType.StoreProcedure; param = command.Parameters.Add (" @ outText ", SqlDbType.Int); Param.direction = parameterDirection.output; sqldatarader dr = cmd.executeReader () while (Dr.Read ()) {} outvalue = command.parameters [@ outtext "] .Value; conn.close ()

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

New Post(0)