C# C语言中的通用Sybase存储过程执行#

C# C语言中的通用Sybase存储过程执行#,c#,stored-procedures,sap-ase,C#,Stored Procedures,Sap Ase,我希望以与在SQL IDE中相同的方式执行Sybase存储过程,即在SQL中执行类似的操作: exec sp_GetCMyDataPerRegion JAPAN' 然而,与此相反,在C代码中,我被迫单独定义每个参数,每个参数都定义了所有这些类型: AseCommand command = new AseCommand(spName, DbConnection); command.CommandType = CommandType.StoredProcedure; AseParameter p

我希望以与在SQL IDE中相同的方式执行Sybase存储过程,即在SQL中执行类似的操作:

exec sp_GetCMyDataPerRegion JAPAN'
然而,与此相反,在C代码中,我被迫单独定义每个参数,每个参数都定义了所有这些类型:

AseCommand command = new AseCommand(spName, DbConnection);
command.CommandType = CommandType.StoredProcedure;

AseParameter param = command.CreateParameter();
param.ParameterName = "@region";
param.AseDbType = AseDbType.VarChar;
param.Direction = ParameterDirection.Input;
param.Value = myValue;
command.Parameters.Add(param);
非常痛苦,到目前为止还没有找到“泛型”的方法,也就是说,只想将存储过程调用封装在具有此类签名的方法中:

public AseDataReader ExecuteStoredProcedure(string spExecutionString){}
你有什么办法吗


提前谢谢你

我有一个SqlDataReader示例,其中函数调用是

ExecuteNonQuery("dbo.[Sp_Skp_UpdateFuncties]", parameters);
这是在类DataBaseManager中,该类保存databaseconnectionstring

public classDataBaseManager
{
...
public int ExecuteStoredProcedure(string storedprocedureNaam, IEnumerable<KeyValuePair<string, object>> parameters)
{
    var sqlCommand = new SqlCommand
    {
        Connection = DatabaseConnectie.SqlConnection,
        CommandType = CommandType.StoredProcedure,
        CommandText = storedprocedureNaam,
    };

    foreach (KeyValuePair<string, object> keyValuePair in parameters)
    {
        sqlCommand.Parameters.Add(
            new SqlParameter { ParameterName = "@" + keyValuePair.Key, Value = keyValuePair.Value ?? DBNull.Value }
        );
    }

    if (sqlCommand == null)
        throw new KoppelingException("Stored procedure ({0}) aanroepen lukt niet", storedprocedureNaam);
    return sqlCommand.ExecuteNonQuery();
}
....
}
公共类数据库管理器 { ... public int ExecuteStoreProcedure(字符串存储过程,IEnumerable参数) { var sqlCommand=新的sqlCommand { Connection=DatabaseConnectie.SqlConnection, CommandType=CommandType.StoredProcess, CommandText=storedprocedureNaam, }; foreach(参数中的KeyValuePair KeyValuePair) { sqlCommand.Parameters.Add( 新的SqlParameter{ParameterName=“@”+keyValuePair.Key,Value=keyValuePair.Value??DBNull.Value} ); } if(sqlCommand==null) 抛出新的KoppelingException(“存储过程({0})aanroepen lukt niet”,storedprocedureNaam); 返回sqlCommand.ExecuteOnQuery(); } .... }
我有一个SqlDataReader示例,其中函数调用是

ExecuteNonQuery("dbo.[Sp_Skp_UpdateFuncties]", parameters);
这是在类DataBaseManager中,该类保存databaseconnectionstring

public classDataBaseManager
{
...
public int ExecuteStoredProcedure(string storedprocedureNaam, IEnumerable<KeyValuePair<string, object>> parameters)
{
    var sqlCommand = new SqlCommand
    {
        Connection = DatabaseConnectie.SqlConnection,
        CommandType = CommandType.StoredProcedure,
        CommandText = storedprocedureNaam,
    };

    foreach (KeyValuePair<string, object> keyValuePair in parameters)
    {
        sqlCommand.Parameters.Add(
            new SqlParameter { ParameterName = "@" + keyValuePair.Key, Value = keyValuePair.Value ?? DBNull.Value }
        );
    }

    if (sqlCommand == null)
        throw new KoppelingException("Stored procedure ({0}) aanroepen lukt niet", storedprocedureNaam);
    return sqlCommand.ExecuteNonQuery();
}
....
}
公共类数据库管理器 { ... public int ExecuteStoreProcedure(字符串存储过程,IEnumerable参数) { var sqlCommand=新的sqlCommand { Connection=DatabaseConnectie.SqlConnection, CommandType=CommandType.StoredProcess, CommandText=storedprocedureNaam, }; foreach(参数中的KeyValuePair KeyValuePair) { sqlCommand.Parameters.Add( 新的SqlParameter{ParameterName=“@”+keyValuePair.Key,Value=keyValuePair.Value??DBNull.Value} ); } if(sqlCommand==null) 抛出新的KoppelingException(“存储过程({0})aanroepen lukt niet”,storedprocedureNaam); 返回sqlCommand.ExecuteOnQuery(); } .... }
谢谢。所以你不需要再精确地确定参数的方向和类型了?我尝试过使用一个命令。ExecuteReader()但无法使其工作。实际上,可以先创建一个“AseParameter param=command.CreateParameter();”,然后定义参数详细信息,使其工作。再次感谢!谢谢所以你不需要再精确地确定参数的方向和类型了?我尝试过使用一个命令。ExecuteReader()但无法使其工作。实际上,可以先创建一个“AseParameter param=command.CreateParameter();”,然后定义参数详细信息,使其工作。再次感谢!