| View previous topic :: View next topic |
| Author |
Message |
yanpakal General User


Joined: 25 Apr 2005 Posts: 6 Location: Oviedo, Asturies, Spain
|
Posted: Mon Apr 25, 2005 11:56 pm Post subject: Error when updating data from dbase table with a macro |
|
|
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 |
|
 |
yanpakal General User


Joined: 25 Apr 2005 Posts: 6 Location: Oviedo, Asturies, Spain
|
Posted: Tue Apr 26, 2005 6:32 am Post subject: Another question related |
|
|
| Theres no exception control in OOo Basic? |
|
| Back to top |
|
 |
Danad OOo Advocate

Joined: 22 Feb 2004 Posts: 293 Location: Brasil
|
Posted: Tue Apr 26, 2005 6:44 pm Post subject: |
|
|
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 |
|
 |
yanpakal General User


Joined: 25 Apr 2005 Posts: 6 Location: Oviedo, Asturies, Spain
|
Posted: Tue Apr 26, 2005 10:46 pm Post subject: |
|
|
| Thanks a lot Danad, now I try it with RowSet. Thanks again. |
|
| Back to top |
|
 |
|