2011-12-13 80 views
2

我有一个Informix数据库,它公开了一些存储过程,我有一个抽象数据访问器来处理与他们的通信,但是我有一个空值的问题。通过ADO.Net命令调用Informix存储过程的最佳/正确方法?

直接可以打电话:

execute procedure some_stored_procedure(1,2,NULL,3) 

,回到正确的结果,我宁愿有没有这个可空场,但它是从我手中。反正我本来试图调用它像这样:

var command = connection.CreateCommand(); 
command.CommandType = CommandTypes.StoredProcedure 
command.CommandText = "some_stored_procedure" 
// Pass in the parameters 

然而这样做导致的Informix抛出一个语法错误,所以不是我不得不去的:

var command = connection.CreateCommand(); 
command.CommandText = "execute procedure some_stored_procedure(?,?,?,?)"; 
// Pass in parameters 

哪些工作,但永远不会传回正确的结果,如果我尝试使参数3为空,则会产生另一个语法错误。我是否错过了一些东西,或者有没有更好的方法来调用这些存储过程?

回答

1

尝试参数化参数(如果使用odbcdriver,则可以使用OdbcParameters),然后通过DbNull.Value(其中需要Null)。

试试这个:

var command = connection.CreateCommand(); 
command.CommandType = CommandTypes.Text; 
command.CommandText = "call some_stored_procedure(?,?,?,?)"; 

command.Parameters.Add(param); //add all your parameters. 
+0

已尝试,它仍然似乎给一个语法错误:( – Grofit

0

格式的查询如下:

 strQuery = string.Format("EXECUTE PROCEDURE Cronos_UpdateStateLegacyProduct ({0})", oValidityProducts.PurchaseId); 

     OdbcConnection oConnection = new OdbcConnection(this.strConnectionString); 
     OdbcCommand oCommand = new OdbcCommand(); 
     oCommand.CommandType = CommandType.StoredProcedure; 
     oCommand.CommandText = strQuery; 
     oCommand.Connection = oConnection; 

     oConnection.Open(); 

     intResult = oCommand.ExecuteNonQuery(); 

问候

-1

如果你正在使用ODBC连接,使用CommandType.StoredProcedure必须使用diferent时过程名称的语法。你的情况:

CommandText = "{ CALL some_stored_procedure(?,?,?,?)}" 

检查此链接了解更多信息:https://support.microsoft.com/en-us/kb/310130

相关问题