Recuperare query da OledbCommandBuilder
BrightSoul
BrightSoul non è online. Ultima attività: 11/05/2009 10.54.44BrightSoul Top Poster
il 2 febbraio 2006 alle 18.56
Contributi | 4.726 messaggi dal 09 febbraio 2002
Salve,
sto utilizzando la classe OleDbCommandBuilder in combinazione con un OleDbDataAdapter per salvare su db le modifiche fatte ad un DataTable.


Dim comando As New OleDbCommandBuilder(myAdapter)
myAdapter.Update(myDataTable)


Questa cosa funziona perfettamente.
Ora però, quello che vorrei fare è estrapolare la query SQL creata dal commandBuilder che è servita al salvataggio dei dati, sia essa DELETE, INSERT o UPDATE.

che proprietà o metodo devo utilizzare? E di quale classe (commandbuilder, dataAdapter o datatable)?

Una prova che ho fatto è stata leggere la proprieta OleDbCommandBuilder.GetDeleteCommand().CommandText, ma ciò che ottengo è una query grezza, piena di punti interrogativi.
DELETE FROM Generi WHERE ((Id = ?) AND ((? = 1 AND Visibile IS NULL) OR (Visibile = ?)) AND ((? = 1 AND Pubblico IS NULL) OR ...

Inoltre, le proprietà DeleteCommand, UpdateCommand e InsertCommand del dataAdapter sono tutte e 3 nothing.
Modificato da BrightSoul il 02 febbraio 2006 19.44 -

- So what you're saying is, if we get in trouble, there's no one to help us out?
- I'm afraid not.
- Fantastic!
Re: Recuperare query da OledbCommandBuilder
andrewz
andrewz non è online. Ultima attività: 05/07/2009 15.23.21andrewz Top Poster
il 2 febbraio 2006 alle 19.52
string ins = myAdapter.InsertCommand.CommandText;
string del = myAdapter.DeleteCommand.CommandText;
string upd = myAdapter.UpdateCommand.CommandText;

Ciao

Andrea Zani
Anche un orologio rotto segna per ben due volte al giorno l'ora esatta.
Re: Recuperare query da OledbCommandBuilder
totti240282
totti240282 non è online. Ultima attività: 04/07/2009 8.13.52totti240282
il 3 febbraio 2006 alle 08.43
336 messaggi dal 27 dicembre 2005
si ma cosi penso si ottenga solo una query parametrica !!!!
Re: Recuperare query da OledbCommandBuilder
BrightSoul
BrightSoul non è online. Ultima attività: 11/05/2009 10.54.44BrightSoul Top Poster
il 3 febbraio 2006 alle 12.36
Contributi | 4.726 messaggi dal 09 febbraio 2002
andrewz ha scritto:
string ins = myAdapter.InsertCommand.CommandText;
string del = myAdapter.DeleteCommand.CommandText;
string upd = myAdapter.UpdateCommand.CommandText;

Ciao


nope, perchè:


le proprietà DeleteCommand, UpdateCommand e InsertCommand del dataAdapter sono tutte e 3 nothing.


mi viene restituito l'errore "Object reference not set to an instance of an object".
myAdapter.UpdateCommand is nothing
restituisce true, e questo capita sia se lo metto prima che dopo l'istruzione myAdapter.Update(myDataTable)


Modificato da BrightSoul il 03 febbraio 2006 13.53 -

- So what you're saying is, if we get in trouble, there's no one to help us out?
- I'm afraid not.
- Fantastic!
Re: Recuperare query da OledbCommandBuilder
BrightSoul
BrightSoul non è online. Ultima attività: 11/05/2009 10.54.44BrightSoul Top Poster
il 3 febbraio 2006 alle 13.55
Contributi | 4.726 messaggi dal 09 febbraio 2002
in alternativa potrei ciclare le datarows e in base al valore datarowstate di ognuna ricostruire la query a mano. In questo caso c'è modo di recuperare il valore dei campi precedente alla modifica per sapere quali di essi sono stati modificati?

Edit: risolto.

if myDataRow("nomecampo").ToString() <> myDataRow("nomecampo", System.Data.DataRowVersion.Original).ToString()
'questo campo è stato modificato > va aggiunto in query
end if

Modificato da BrightSoul il 03 febbraio 2006 21.28 -

- So what you're saying is, if we get in trouble, there's no one to help us out?
- I'm afraid not.
- Fantastic!

Vai a:
Torna al forum |   Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.

COMMUNITY
ULTIMI MESSAGGI
MEDIA
IN EVIDENZA
MISC
Powered by .db Forums "Caesar Reborn" v. 2009.6.9