C#如何执行存储过程
以Oracle为例,其它数据库仅改变数据库对象就可以。下面是带参数的,不带参数的话paramete为null即可。
参数对应
public static int UploadStartCloseSoftInfo(string[] args)
{
OracleParameter parameter1 = new OracleParameter(参数名1, OracleType.类型);
parameter1.Value =类型转换(args[0]);
OracleParameter parameter2 = new OracleParameter(参数名2, OracleType.类型);
parameter2.Value =类型转换(args[1]);
... ...
OracleParameter parametern = new OracleParameter(参数名n, OracleType.类型);
parametern.Value =类型转换(args[n-1]);
OracleParameter[] parameter
= {parameter1,parameter2,...,parametern};
return SDProvider.RunProcedure(存储过程名, parameter);
}
}
}
public static int UploadStartCloseSoftInfo(string[] args)
{
OracleParameter parameter1 = new OracleParameter(参数名1, OracleType.类型);
parameter1.Value =类型转换(args[0]);
OracleParameter parameter2 = new OracleParameter(参数名2, OracleType.类型);
parameter2.Value =类型转换(args[1]);
... ...
OracleParameter parametern = new OracleParameter(参数名n, OracleType.类型);
parametern.Value =类型转换(args[n-1]);
OracleParameter[] parameter
= {parameter1,parameter2,...,parametern};
return SDProvider.RunProcedure(存储过程名, parameter);
}
}
}
执行
public class SDProvider
{
public static string GetConnectionString()
{
string conStr =连接数据库字符串;
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(param
补充:软件开发 , C# ,