5.360 messaggi dal 09 febbraio 2002
Contributi
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!
string ins = myAdapter.InsertCommand.CommandText;
string del = myAdapter.DeleteCommand.CommandText;
string upd = myAdapter.UpdateCommand.CommandText;

Ciao

Andrea Zani
Undicesimo comandamento: NON utilizzare Explorer 6
558 messaggi dal 27 dicembre 2005
si ma cosi penso si ottenga solo una query parametrica !!!!
5.360 messaggi dal 09 febbraio 2002
Contributi
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!
5.360 messaggi dal 09 febbraio 2002
Contributi
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!

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.