Pagina 1 di 1
Base:Inserire nuovo record(risolto)
Inviato: venerdì 10 settembre 2010, 17:57
da veterinario
Il mio problema è il seguente: il database è composto da una tabella "evento" costituita dai campi "id" (contatore) "data" e "soggetto" . Non so come scrivere una macro associata a un bottone che mi crei un nuovo record nella tabella "evento "riempiendo i campi con valori decisi a priori. Come potrei fare?
inserire nuovo record
Inviato: venerdì 10 settembre 2010, 20:50
da veterinario
Il mio problema è il seguente: il database è composto da una tabella "evento" costituita dai campi "id" (contatore) "data" e "soggetto" . Mi servirebbe una macro associata a un bottone che mi crei un nuovo record nella tabella "evento "riempiendo i campi con valori decisi a priori. Ho provato così ma non funziona, assegna al campo data un valore non corretto.
sub data
dim data as date
oForm = ThisComponent.DrawPage.Forms.cliente.animale.evento
data = date
oForm.updateString(oForm.findColumn ("data"), data)
end sub
Re: Base:Inserire nuovo record
Inviato: domenica 12 settembre 2010, 20:43
da Raimondo
Devi usare un comando SQL
Ti posto questa sub per modificare una tabella con nome = "Nometabella"
adattala alle tue esigenze
Codice: Seleziona tutto
sub Transfer(Fileinf as file_info,Nometabella$)
[code]
dim Cdata as Date,dd as new com.sun.star.util.DateTime
'aprire nella tabella Nometabella un rowset
' e inserire i dati con i vari Update....
dim oContext as object
dim oSorgente as object
'dim oInteractionHandler as object
dim oConnection as object
'dim oRequete as object
'dim oResulset as object
'dim Retour as integer
oContext = createUnoService("com.sun.star.sdb.DatabaseContext")
oSorgente = oContext.getByName("dBFile") 'Metti il nome del tuo database
oConnection=oSorgente.getconnection("","") 'utente, pwd se ci sono
oRowSet = createUnoService("com.sun.star.sdb.RowSet")
oSql = "SELECT * FROM " & Nometabella
with oRowSet
.activeConnection = oConnection
.CommandType=com.sun.star.sdb.CommandType.TABLE
.Command=Nometabella
.execute '
.movetoinsertrow()
.updateLong(1,Fileinf.ID) ' (1) sta per prima colonna NOTA usare il metodo update____ appropriato
.updateShort(2,Fileinf.Tipo)
.updateString(3,Fileinf.subpath)
.updateString(4,Fileinf.nome)
.updateLong(5,Fileinf.lung)
Cdata=Cdate(Fileinf.data) ' convertire la stringa Fileinf.data nella Variabile strutturata dd com.sun.star.util.DateTime
converti(Cdata,dd)
.updateTimestamp(6,dd)
.updateInt(7,Fileinf.liv)
.updateString(8,"") 'Md5
.updateLong(9,Fileinf.IDdir) 'Md5
.updateLong(10,Fileinf.PuntID)
.insertrow()
'msgbox .getrow()
end with
'xray oRowset
end sub
sub converti(Cdata as date ,dd as new com.sun.star.util.DateTime)
with dd
.Year=Year(Cdata)
.Month=Month(Cdata)
.Day=Day(Cdata)
.Hours=Hour(Cdata)
.Minutes=Minute(Cdata)
.Seconds=Second(Cdata)
.HundredthSeconds=0
end with
end sub
Ovviamente
La tua variabile non sarà FileInf (che è una mia variabile strutturata).
Spero di esserti stato utile.
Ciao
Re: Base:Inserire nuovo record
Inviato: lunedì 13 settembre 2010, 15:14
da veterinario
Grazie mille però alla fine l'ho risolta in questo modo:
Sub data2
dim strDate as string
dest= ThisComponent.DrawPage.forms.cliente.animale.evento
strDate = Year(date)& "-" & Month(date) &"-"& Day(date)
dest.moveToInsertRow()
dest.updateNull(1)
dest.updateNull(2)
dest.updateNull(3)
dest.updateString(4, strDate)
dest.insertRow()
end sub
sembra funzionare
Re: Base:Inserire nuovo record
Inviato: lunedì 13 settembre 2010, 19:01
da Raimondo
OK segna il problema come RISOLTO.
Ciao.
Re: Base:Inserire nuovo record
Inviato: mercoledì 15 settembre 2010, 22:08
da xergio
In alternativa, se ti è più comodo, puoi anche usare un comando sql, come descritto qui
http://user.services.openoffice.org/it/ ... 97&start=0