我可以在访问项目中使用持久性(Oracle)记录集吗?

时间:2016-03-07 10:55:45

标签: ms-access access-vba recordset persistent

显然,您无法使用recordset t在Access Project中设置表单的Oracle-based recordse属性,但有没有办法在Access form中显示或选择这些记录}?

2 个答案:

答案 0 :(得分:0)

  1. 在ODBC控制面板中为Oracle数据库添加DSN条目

  2. 在Access中,创建一个新查询,将其定义为Pass-Through,在查询文本中键入您想要的任何内容,否则您无法保存它( SELECT * 即可)。此pass-trough查询将用于从Oracle检索数据并在表单中显示它们,您将在VBA代码中即时定义它的SQL

  3. 在您的表单代码中,执行以下操作:

  4. getTimeDifference(date, t);
    
    private void getTimeDifference(String pDate, TextView time) {
        int diffInDays = 0;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        format.setTimeZone(TimeZone.getTimeZone("GMT"));
        Calendar c = Calendar.getInstance();
        String formattedDate = format.format(c.getTime());
    
        Date d1 = null;
        Date d2 = null;
        try {
    
            d1 = format.parse(formattedDate);
            d2 = format.parse(pDate);
            long diff = d1.getTime() - d2.getTime();
    
            diffInDays = (int) (diff / (1000 * 60 * 60 * 24));
            if (diffInDays > 0) {
                if (diffInDays == 1) {
                    time.setText(diffInDays + " day ago");
                } else {
                    time.setText(diffInDays + " days ago");
                }
            } else {
                int diffHours = (int) (diff / (60 * 60 * 1000));
                if (diffHours > 0) {
                    if (diffHours == 1) {
                        time.setText(diffHours + " hr ago");
                    } else {
                        time.setText(diffHours + " hrs ago");
                    }
                } else {
    
                    int diffMinutes = (int) ((diff / (60 * 1000) % 60));
                    if (diffMinutes == 1) {
                        time.setText(diffMinutes + " min ago");
                    } else {
                        time.setText(diffMinutes + " mins ago");
                    }
    
                }
            }
    
        } catch (ParseException e) {
            // System.out.println("Err: " + e);
            e.printStackTrace();
        }
    
    }
    

答案 1 :(得分:0)

我通过在后端服务器上创建一个表来解决问题,在VBA中循环遍历基于oracle的记录集,然后使用存储过程在(sql server)表中创建新记录,该存储过程从oracle获取字段基于记录集作为参数,并将这些值作为sql server表中的记录插入。