OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Error when updating data from dbase table with a macro

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
yanpakal
General User
General User


Joined: 25 Apr 2005
Posts: 6
Location: Oviedo, Asturies, Spain

PostPosted: Mon Apr 25, 2005 11:56 pm    Post subject: Error when updating data from dbase table with a macro Reply with quote

Im learning OOo Base to use macros to make custom form button acctions. When I try to update data from a table with the next code, the macro crashes and show me this error:

OpenOffice.org 1.9.9.5

Error of ejecuccion of BASIC.
It has happened the exception
Type: com.sun.star.lang.DisposedException
Message: .

Macro code:
Code:

REM  *****  BASIC  *****
option explicit
Sub Main
   Dim DBContext
   Dim DataSource
   Dim Conection
   Dim IHandler
   Dim Statement
   Dim ResultSet
   dim Query as String
   dim ColumnID as integer
   dim City as String   
   dim RowUpdate
   dim Out as string
   dim SqlUpdate as string
   dim NewData as string, OldData as string
   
   
   DBContext = createUnoService("com.sun.star.sdb.DatabaseContext")
   DataSource = DBContext.getByName("info")
   
   If Not DataSource.IsPasswordRequired Then
      Conection = DataSource.GetConnection("","")
   Else
      IHandler = createUnoService("com.sun.star.sdb.InteractionHandler")
      Conection = DataSource.ConnectWithCompletion(InteractionHandler)
   End If
   
   Statement = Conection.createStatement()
   
   Statement.setPropertyValue("ResultSetConcurrency", com.sun.star.sdbc.ResultSetConcurrency.UPDATABLE)
 
   Query = "select * from 'City'"   
   ResultSet = Statement.executeQuery(Query)
   
   
   If Not IsNull(ResultSet) Then
      ColumnID = ResultSet.findColumn("name")
      NewData= "Oviedo"
      OldData= "Madrid"
      Out= ""
      While ResultSet.next
         City= ResultSet.getString(ColumnID)
         Out= Out + City  + Chr(13)
         if City= OldData then
            Sql= "UPDATE 'City' SET "&chr(34)&"name"&chr(34)&" = '"&newData &"' WHERE "&chr(34)&"name"&chr(34)&" = '"& oldData &"'"
            Statement.executeUpdate(Sql)
         end if   
      Wend
      ' to see data before      
      msgbox Out
   
      While ResultSet.next
         City= ResultSet.getString(ColumnID)
         Out= Out + City  + Chr(13)
      Wend
      'to see data after
      msgbox Out
   End If

End Sub
Back to top
View user's profile Send private message
yanpakal
General User
General User


Joined: 25 Apr 2005
Posts: 6
Location: Oviedo, Asturies, Spain

PostPosted: Tue Apr 26, 2005 6:32 am    Post subject: Another question related Reply with quote

Theres no exception control in OOo Basic?
Back to top
View user's profile Send private message
Danad
OOo Advocate
OOo Advocate


Joined: 22 Feb 2004
Posts: 293
Location: Brasil

PostPosted: Tue Apr 26, 2005 6:44 pm    Post subject: Reply with quote

Time ago (OO.o 1.0.x), I couldn't update dBase tables with SQL.
So I used the service RowSet and methods of interfaces XResultSetUpdate and XRowUpdate to do that.

Quote:

Theres no exception control in OOo Basic?

No, at least like Java. But you can use the Basic function On Error Goto to handle UNO
runtime exceptions. There's a sample at section 3.4.3 in Developer's Guide.

HTH
Back to top
View user's profile Send private message
yanpakal
General User
General User


Joined: 25 Apr 2005
Posts: 6
Location: Oviedo, Asturies, Spain

PostPosted: Tue Apr 26, 2005 10:46 pm    Post subject: Reply with quote

Thanks a lot Danad, now I try it with RowSet. Thanks again.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group