.NET:使用ODBC使用参数化存储过程存储数据表

时间:2017-09-18 16:53:11

标签: c# stored-procedures datatable odbc dataadapter

坚持填充数据表。它是关于填充数据表?,它是关于传递参数?,它是关于一个没有sys_refcursor的过程?试过这个:

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 (OdbcDataAdapter da = new OdbcDataAdapter())
            {
                da.SelectCommand = new OdbcCommand("{ call PKG_GEONET_REPORTS.GET_ORDINARY_CLIENT(?, ?, ?) }", conn);
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                //da.SelectCommand.CommandType = System.Data.CommandType.Text;

                da.SelectCommand.Parameters.AddWithValue("client_in", idElemento.ToString());
                da.SelectCommand.Parameters.AddWithValue("layer_in", layerName);
                da.SelectCommand.Parameters.AddWithValue("client_data", ParameterDirection.Output);

                DataSet ds = new DataSet();
                da.Fill(ds, "data");

                DataTable dt = ds.Tables["data"];

                /*foreach (DataRow row in dt.Rows)
                {
                    dt.Rows.Add(row);
                }*/
                return dt;
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }
}

和此:

    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.AddWithValue("client_in", idElemento.ToString());
                    Command.Parameters.AddWithValue("layer_in", layerName);
                    Command.Parameters.AddWithValue("client_data", ParameterDirection.Output);
                    using (OdbcDataAdapter da = new OdbcDataAdapter(Command))
                    {
                        DataTable dt = new DataTable();
                        da.Fill(dt);
                        return dt;
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
    }

我没有错误消息,我的应用无法显示结果,我只是看到一个空白的屏幕。

我的conexion字符串是:

"Driver={Microsoft ODBC for Oracle};...;"

我的存储过程是:

PROCEDURE GET_ORDINARY_CLIENT (client_in IN varchar2, layer_in IN varchar2, client_data OUT SYS_REFCURSOR );

0 个答案:

没有答案