Taking Oracle as an example, other databases only need to change database objects. The following is a parameter. If there is no parameter, paramete is null.
Parameter correspondence
Public static int UploadStartCloseSoftInfo (string [] args)
{
OracleParameter parameter1 = new OracleParameter (parameter 1, OracleType. type );
Parameter1.Value = type conversion (args [0]);
OracleParameter parameter2 = new OracleParameter (parameter name 2, OracleType. type );
Parameter2.Value = type conversion (args [1]);
......
OracleParameter parametern = new OracleParameter (parameter name n, OracleType. type );
Parametern. Value = type conversion (args [n-1]);
OracleParameter [] parameter
= {Parameter1, parameter2,..., parametern };
Return SDProvider. RunProcedure (stored procedure name, parameter );
}
}
}
Public static int UploadStartCloseSoftInfo (string [] args)
{
OracleParameter parameter1 = new OracleParameter (parameter 1, OracleType. type );
Parameter1.Value = type conversion (args [0]);
OracleParameter parameter2 = new OracleParameter (parameter name 2, OracleType. type );
Parameter2.Value = type conversion (args [1]);
......
OracleParameter parametern = new OracleParameter (parameter name n, OracleType. type );
Parametern. Value = type conversion (args [n-1]);
OracleParameter [] parameter
= {Parameter1, parameter2,..., parametern };
Return SDProvider. RunProcedure (stored procedure name, parameter );
}
}
}
Run
Public class SDProvider
{
Public static string GetConnectionString ()
{
String conStr = connection string;
Return conStr;
}
Public static int RunProcedure (string prName, IDataParameter [] parameters)
{
Try
{
Using (OracleConnection connection =
New OracleConnection (GetConnectionString ()))
{
Connection. Open ();
OracleCommand command =
BuildQueryCommand (connection, storedProcName, parameters );
Return command. ExecuteNonQuery ();
}
}
Catch
{
}
Return 0;
}
Private static OracleCommand BuildQueryCommand
(OracleConnection connection,
String storedProcName,
IDataParameter [] parameters)
{
OracleCommand command = new OracleCommand (storedProcName, connection );
Command. CommandType = CommandType. StoredProcedure;
If (parameters! = Null)
{
Foreach (OracleParameter parameter in parameters)
{
Command. Parameters. Add (parameter );
}
}
Return command;
}
}
Public class SDProvider
{
Public static string GetConnectionString ()
{
String conStr = connection string;
Return conStr;
}
Public static int RunProcedure (string prName, IDataParameter [] parameters)
{
Try
{
Using (OracleConnection connection =
New OracleConnection (GetConnectionString ()))
{
Connection. Open ();
OracleCommand command =
BuildQueryCommand (connection, storedProcName, parameters );
Return command. ExecuteNonQuery ();
}
}
Catch
{
}
Return 0;
}
Private static OracleCommand BuildQueryCommand
(OracleConnection connection,
String storedProcName,
IDataParameter [] parameters)
{
OracleCommand command = new OracleCommand (storedProcName, connection );
Command. CommandType = CommandType. StoredProcedure;
If (parameters! = Null)
{
Foreach (OracleParameter parameter in parameters)
{
Command. Parameters. Add (parameter );
}
}
Return command;
}
}
Note:
1. The stored procedure name is correct.
2. Parameter 1 and parameter 2. These names must be the same as the parameter names in the stored procedure. The order and type must be consistent.
From Poplar