Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
App. WinForms / WPF .NET
Chiamata a Stored di insert tramite ODBC. Non riesco a valutare il @RE...
martedì 20 gennaio 2009 - 10.33
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
Giobbetto
Profilo
| Newbie
2
messaggi | Data Invio:
mar 20 gen 2009 - 10:33
Salve a tutti.
Ho un problema con VB.NET 2008 sotto XP sp3 con la chiamata ad una stored di insert.
Inizialmente usavo la SQLCommand in questo modo:
***************************************************************************
Dim oCmd as new SQLCommand
Dim oCon as New SQLConnection("MiaConn")
oCmd.CommandText = "MiaStored"
oCmd.CommandType = CommandType.StoredProcedure
oCmd.Connection = oCon
SQLCommandBuilder.DeriveParameter(oCmd)
oCmd.Parameter("@Param1").Value = MioValore1
oCmd.Parameter("@Param2").Value = MioValore2
oCmd.ExecuteNonQuery
IF oCmd.Parameter(0).Value = 0 Then 'Oppure uso .Parameter("@RETURN_VALUE")
Throw new Exception("Errore non scritto nulla")
EndIf
***************************************************************************
Cosi ha sempre funzionato tutto.
Poi ho avuto la necessità di usare ODBC.
Quindi ho convertito tutto in ODBC in questo modo:
***************************************************************************
Dim oCmd as new ODBCCommand
Dim oCon as New ODBCConnection("MiaConn")
oCmd.CommandText = "MiaStored"
oCmd.CommandType = CommandType.StoredProcedure
oCmd.Connection = oCon
ODBCCommandBuilder.DeriveParameter(oCmd)
oCmd.Parameter("@Param1").Value = MioValore1
oCmd.Parameter("@Param2").Value = MioValore2
oCmd.ExecuteNonQuery
IF oCmd.Parameter(0).Value = 0 Then 'Oppure uso .Parameter("@RETURN_VALUE")
Throw new Exception("Errore non scritto nulla")
EndIf
***************************************************************************
Sono iniziati i problemi.
All'esecuzione della query va in errore perchè dice che il @Param1 non è stato passato.
Allora ho trovato la soluzione sostituendo il codice con questo:
***************************************************************************
Dim oCmd as new ODBCCommand
Dim oCon as New ODBCConnection("MiaConn")
oCmd.CommandText = "{call MiaStored(?,?)}"
oCmd.CommandType = CommandType.StoredProcedure
oCmd.Connection = oCon
oCmd.Parameter.Add("@Param1", OdbcType.VarChar).Value = MioValore1
oCmd.Parameter.Add("@Param2", OdbcType.VarChar).Value = MioValore2
oCmd.ExecuteNonQuery
***************************************************************************
E la stored funziona. Ma c'è un modo per usare l'ODBCCommandbuilder per derivare i parametri? Boh!
Io non ci sono riuscito...
Volendo testare il @Return_Value ho aggiunto il parametro:
oCmd.Parameter.Add("@Return_Value", OdbcType.Int).Direction = ParameterDirection.ReturnValue
senza modificare il numero di ? nel command text perchè altrimenti da errore dicendo che sono stati passati
troppo parametri.
Dopo ExecuteNonQuery ho aggiunto il test del parametro "@Return_Value" ma torna sempre DBNULL quando in
realtà eseguendo la stored da SQL il Return Value è valorizzato.
Non volevo aggiungere un parametro di OUTPUT a tutte le stored per ovviare a questo problema.
Avete qualche idea?
Magari anche su come usare il DeriveParameter?
Grazie in anticipo
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !