Chinaunix首页 | 论坛 | 博客
  • 博客访问: 685263
  • 博文数量: 194
  • 博客积分: 7067
  • 博客等级: 少将
  • 技术积分: 2008
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-09 14:48
个人简介

我很好

文章分类

全部博文(194)

文章存档

2019年(1)

2018年(1)

2017年(3)

2015年(2)

2012年(2)

2011年(1)

2010年(27)

2009年(15)

2008年(142)

分类: WINDOWS

2008-08-21 21:15:47

REPORT  z_barry_access.

INCLUDE ole2incl.

CONSTANTS: provider(40)  VALUE 'Provider=Microsoft.Jet.OLEDB.4.0',
           security(40)  VALUE 'Persist Security Info=False',
           datasource(30) VALUE 'Data Source=D:\db1.mdb'.
DATA: o_conn      TYPE ole2_object,
      o_recordset TYPE ole2_object,
      o_field     TYPE ole2_object.
DATA: con_str(128) ,sql_str(400).
DATA: BEGIN OF ty_itab OCCURS 0,
        mandt LIKE t001-mandt ,
        bukrs LIKE t001-bukrs ,
        butxt LIKE t001-butxt ,
      END OF ty_itab.
DATA: itab LIKE TABLE OF  ty_itab WITH HEADER LINE.

START-OF-SELECTION.
  PERFORM oledb_open.
  PERFORM sql_select.
  PERFORM sql_update.
  PERFORM sql_close.

*&---------------------------------------------------------------------*
*&      Form  oledb_open
*&---------------------------------------------------------------------*
FORM oledb_open.
  CONCATENATE  provider ';' security ';' datasource INTO con_str.
  CREATE OBJECT o_conn 'ADODB.Connection'.
  SET PROPERTY OF o_conn 'Provider' = provider.
  SET PROPERTY OF o_conn 'con_str' = con_str.
  CALL METHOD OF o_conn 'Open'.
ENDFORM.                    "OLEDB_open

*&---------------------------------------------------------------------*
*&      Form  sql_select
*&---------------------------------------------------------------------*
FORM sql_select .
  DATA: rs_eof TYPE i.

  sql_str = 'select mandt, bukrs,butxt from TEST_ZTEST'.
  CALL METHOD OF o_conn 'Execute' = o_recordset
    EXPORTING
    #1 = sql_str.

  GET PROPERTY OF o_recordset 'EOF' = rs_eof.
  REFRESH itab.

  WHILE rs_eof NE 1.
    CALL METHOD OF o_recordset 'fields' = o_field
      EXPORTING
      #1 = 0.
    GET PROPERTY OF o_field 'Value' = itab-mandt.

    CALL METHOD OF o_recordset 'fields' = o_field
      EXPORTING
      #1 = 1.
    GET PROPERTY OF o_field 'Value' =  itab-bukrs.

    CALL METHOD OF o_recordset 'fields' = o_field
      EXPORTING
      #1 = 2.
    GET PROPERTY OF o_field 'Value' = itab-butxt.

    APPEND itab.

    CALL METHOD OF o_recordset 'MoveNext'.
    GET PROPERTY OF o_recordset 'EOF' = rs_eof.
  ENDWHILE.
  LOOP AT itab.
    WRITE: / itab-mandt,itab-bukrs,itab-butxt.
  ENDLOOP.
ENDFORM.                    "sql_select
*&---------------------------------------------------------------------*
*&      Form  sql_update
*&---------------------------------------------------------------------*
FORM sql_update .
  CONCATENATE 'update TEST_ZTEST set butxt=' '''' 'SAP AG' ''''
              ' where bukrs=' '''' '2005' '''' INTO sql_str.
  CALL METHOD OF o_conn 'Execute' = o_recordset
    EXPORTING
    #1 = sql_str.
ENDFORM.                    "sql_update

*&---------------------------------------------------------------------*
*&      Form  sql_close
*&---------------------------------------------------------------------*
FORM sql_close.
  CALL METHOD OF o_recordset 'Close'.
  CALL METHOD OF o_conn 'Close'.
  FREE OBJECT o_recordset.
  FREE OBJECT o_conn.
ENDFORM.                    "sql_close

文件: 080803110743.rar
大小: 6KB
下载: 下载
阅读(738) | 评论(4) | 转发(0) |
给主人留下些什么吧!~~

nanyunjian2008-10-18 13:55:38

修改如下两处可以处理SQL数据库 1、CONSTANTS: provider(100) VALUE 'Provider=SQLOLEDB;Data Source=SQLserver;uid=sa;pwd=123456;database=ZTEST', 2、con_str = provider. 查询语句 sql_str = 'select top 10 * from ztest'.

nanyunjian2008-10-18 13:43:48

按照老白的就没有错了,上次作测试的时候CALL METHOD OF o_conn 'Open'.没有出错,是连通了库,没数据出来。

qdbarry2008-10-16 12:27:06

SET PROPERTY OF o_conn 'con_str' = con_str. 改为: SET PROPERTY OF o_conn 'ConnectionString' = con_str.

chinaunix网友2008-09-18 09:42:19

联接不成功,CALL METHOD OF o_conn 'Open'.报错了。 铁木真南 你试过可以吗??