简体   繁体   English

.net:使用存储过程中的dataAdapter存储.net数据表

[英].net: Storing a .net datatable with dataAdapter from a stored procedure

I have a stored procedure called 我有一个存储过程称为

GET_CLIENT(IN VARCHAR2, IN VARCHAR2, OUT SYS REF_CURSOR)

I am trying to store their results in ConnectAndQuery data table. 我正在尝试将其结果存储在ConnectAndQuery数据表中。

It results in this error: 它导致此错误:

System.Data.Odbc.OdbcException: ERROR [42000] [Microsoft][ODBC driver for Oracle][Oracle] System.Data.Odbc.OdbcException:错误[42000] [Microsoft] [Oracle的ODBC驱动程序] [Oracle]
ORA-00900: invalid SQL statement ORA-00900:无效的SQL语句

at ConexionBD.ConnectAndQuery(String layerName, Decimal idElemento, String idElementoString, String conexion). 在ConexionBD.ConnectAndQuery(String layerName,Decimal idElemento,String idElementoString,String conexion)中。

My code: 我的代码:

public DataTable ConnectAndQuery(string layerName, decimal idElemento, string idElementoString, string conexion)
    {
        Logger.Debug("App_Code/ConexionBD.cs: using (OdbcConnection connection = new OdbcConnection(Driver={Microsoft ODBC for Oracle}; + conexion ");
        using (OdbcConnection conn = new OdbcConnection(conexion))
        {
            try
            {
                using (OdbcCommand Command = new OdbcCommand("{ call PKG_GEONET_REPORTS.GET_ORDINARY_CLIENT(?, ?, ?) }", conn))
                {
                    Command.CommandType = CommandType.StoredProcedure;
                    Command.Parameters.Add("client_in", OracleType.VarChar).Value = idElemento.ToString();
                    Command.Parameters.Add("layer_in", OracleType.VarChar).Value = layerName;
                    Command.Parameters.Add("client_data", OracleType.Cursor).Direction = ParameterDirection.Output;
                    using (OdbcDataAdapter da = new OdbcDataAdapter(Command))
                    {
                        DataTable dt = new DataTable();
                        da.Fill(dt);
                        return dt;
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
    }

Change your SQL text in your command. 在命令中更改SQL文本。

da.SelectCommand = new OdbcCommand(
    "{ call PKG_NAME.GET_CLIENT(?, ?, ?) }",
    conn);
  • Your 1st parameter "layer_in" should be OracleType.VarChar to match your stored procedure 1st parameter DataType, should it not? 您的第一个参数“ layer_in”应为OracleType.VarChar以与您的存储过程第一个参数DataType相匹配,不是吗?
  • da.Fill(ds); should be used instead of da.Fill(ds,"RESULT_NAME?"); 应该代替da.Fill(ds,"RESULT_NAME?"); if you dont know the name of the result set. 如果您不知道结果集的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM