473,465 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

IDbDataAdapter e RowUpdating

Ciao a tutti,
sto cercando di realizzare una classe (ProviderFactory) che mi consenta di
scrivere del codice a prescindere dal provider utilizzato per accedere ai
dati. Al momento gestisco i classici SqlClient, ODBC, OleDb e Oracle.
Ho dichiarato nel codice client le variabili utilizzando le interfacce
(IDbConnection, IDbCommand, ecc..) Il codice funzionava alla grande finchè
non mi sono imbattuto nel seguente problema:

IDbDataAdapter non supporta gli eventi RowUpdating e RowUpdated, a
differenza degli equivalenti oggetti (SqlDataProvider, ecc...).
Tali eventi sono ovviamente indispensabili per eseguire delle update
complesse o anche per solo scopo di debug.
Come posso fare a scrivere del buon codice ObjectOriented senza rieseguire
il cast all'indietro ?

Ogni idea è ben accetta. Grazie

Maurizio
Jul 21 '05 #1
4 1649
Quale e' il problema usando la classe astratta DataAdapter come base class e
fargli implementare la IDbDataAdapter come fa il framework? (magari mi sono
perso qualcosa...)

HTH

--
Corrado Cavalli [Microsoft .NET MVP-MCP]
UGIdotNET - http://www.ugidotnet.org
Weblog: http://www.ugidotnet.org/710.blog


Jul 21 '05 #2
L'idea è di avere nel codice client delle istruzioni come le seguenti:

Dim pf As New MyProviderFactory
Dim cb As MyCommandBuilder

Dim cn As IDbConnection
Dim cmm As IDbCommand
Dim da As IDataAdapter
Dim db As IDbDataAdapter
Dim currDs As DataSet

Dim Connection As String
Dim SqlCommand As String

Connection = TxtConnection.Text
SqlCommand = TxtStatement.Text

pf.Provider = ProviderType.SqlServer

cn = pf.CreateConnection(Connection)
da = pf.CreateDataAdapter(SqlCommand, cn)
db = CType(da, IDbDataAdapter)
currDs = New DataSet
db.Fill(currDs)
DGData.DataSource = currDs
currDataSet = currDs

Tranne dove è specificato il tipo di connessione (pf.Provider =
ProviderType.SqlServer) il codice è assolutamente generico e prescinde dal
provider utilizzato. La mia idea è di far uso degli eventi esposti dai
DataAdapter (RowUpdating, RowUpdated) ma, utilizzando il codice precendete,
non posso agganciarmi in quanto IDbDataAdapter non espone gli eventi. Ho
verificato che anche la classe base DBDataAdpater non espone alcun evento.

"Corrado Cavalli [MVP]" <co*****************@mvps.org> wrote in message
news:#M**************@tk2msftngp13.phx.gbl...
Quale e' il problema usando la classe astratta DataAdapter come base class e fargli implementare la IDbDataAdapter come fa il framework? (magari mi sono perso qualcosa...)

HTH

--
Corrado Cavalli [Microsoft .NET MVP-MCP]
UGIdotNET - http://www.ugidotnet.org
Weblog: http://www.ugidotnet.org/710.blog

Jul 21 '05 #3
Ti consiglio di dare un'occhiata alla bella presentazione di Andrea
Saltarello su ado.net al link:
http://www.ugidotnet.org/workshops/w...x?WorkshopID=5

Uno degli esempi è proprio chiamato AbstractADO per realizzare ciò che vuoi.

Il problema principale è che le interfacce delle ado supportano il minimo
comun denominatore delle classi Sql, Oledb, Oracle,...
Perciò la risposta non può essere quella più ovvia di usare le interfacce
come mezzo per arrivare a sfruttare la totale potenza dei vari provider.
Per esempio Sql supporta ExecuteXmlReader e tu potresti decidere di
sopperire alla mancanza di questo metodo negli altri provider.

Un buono spunto viene da quell'esempio di Andrea.

--
Raffaele Rialdi
Microsoft .NET MVP http://mvp.support.microsoft.com
UGIdotNET - User Group Italiano .NET http://www.ugidotnet.org

"Maurizio" <ma*******************************@cezannesw.com > wrote in
message news:O1**************@TK2MSFTNGP12.phx.gbl...
L'idea è di avere nel codice client delle istruzioni come le seguenti:

Dim pf As New MyProviderFactory
Dim cb As MyCommandBuilder

Dim cn As IDbConnection
Dim cmm As IDbCommand
Dim da As IDataAdapter
Dim db As IDbDataAdapter
Dim currDs As DataSet

Dim Connection As String
Dim SqlCommand As String

Connection = TxtConnection.Text
SqlCommand = TxtStatement.Text

pf.Provider = ProviderType.SqlServer

cn = pf.CreateConnection(Connection)
da = pf.CreateDataAdapter(SqlCommand, cn)
db = CType(da, IDbDataAdapter)
currDs = New DataSet
db.Fill(currDs)
DGData.DataSource = currDs
currDataSet = currDs

Tranne dove è specificato il tipo di connessione (pf.Provider =
ProviderType.SqlServer) il codice è assolutamente generico e prescinde dal
provider utilizzato. La mia idea è di far uso degli eventi esposti dai
DataAdapter (RowUpdating, RowUpdated) ma, utilizzando il codice precendete, non posso agganciarmi in quanto IDbDataAdapter non espone gli eventi. Ho
verificato che anche la classe base DBDataAdpater non espone alcun evento.

"Corrado Cavalli [MVP]" <co*****************@mvps.org> wrote in message
news:#M**************@tk2msftngp13.phx.gbl...
Quale e' il problema usando la classe astratta DataAdapter come base
class e
fargli implementare la IDbDataAdapter come fa il framework? (magari mi

sono
perso qualcosa...)

HTH

--
Corrado Cavalli [Microsoft .NET MVP-MCP]
UGIdotNET - http://www.ugidotnet.org
Weblog: http://www.ugidotnet.org/710.blog


Jul 21 '05 #4
Grazie,
ho scaricato il codice e le slides. Spero che possano essermi utili.

Maurizio
"Raffaele Rialdi [MVP]" <malta@n0spam_vevy.com> wrote in message
news:#x**************@TK2MSFTNGP12.phx.gbl...
Ti consiglio di dare un'occhiata alla bella presentazione di Andrea
Saltarello su ado.net al link:
http://www.ugidotnet.org/workshops/w...x?WorkshopID=5

Uno degli esempi è proprio chiamato AbstractADO per realizzare ciò che vuoi.
Il problema principale è che le interfacce delle ado supportano il minimo
comun denominatore delle classi Sql, Oledb, Oracle,...
Perciò la risposta non può essere quella più ovvia di usare le interfacce
come mezzo per arrivare a sfruttare la totale potenza dei vari provider.
Per esempio Sql supporta ExecuteXmlReader e tu potresti decidere di
sopperire alla mancanza di questo metodo negli altri provider.

Un buono spunto viene da quell'esempio di Andrea.

--
Raffaele Rialdi
Microsoft .NET MVP http://mvp.support.microsoft.com
UGIdotNET - User Group Italiano .NET http://www.ugidotnet.org

"Maurizio" <ma*******************************@cezannesw.com > wrote in
message news:O1**************@TK2MSFTNGP12.phx.gbl...
L'idea è di avere nel codice client delle istruzioni come le seguenti:

Dim pf As New MyProviderFactory
Dim cb As MyCommandBuilder

Dim cn As IDbConnection
Dim cmm As IDbCommand
Dim da As IDataAdapter
Dim db As IDbDataAdapter
Dim currDs As DataSet

Dim Connection As String
Dim SqlCommand As String

Connection = TxtConnection.Text
SqlCommand = TxtStatement.Text

pf.Provider = ProviderType.SqlServer

cn = pf.CreateConnection(Connection)
da = pf.CreateDataAdapter(SqlCommand, cn)
db = CType(da, IDbDataAdapter)
currDs = New DataSet
db.Fill(currDs)
DGData.DataSource = currDs
currDataSet = currDs

Tranne dove è specificato il tipo di connessione (pf.Provider =
ProviderType.SqlServer) il codice è assolutamente generico e prescinde dal provider utilizzato. La mia idea è di far uso degli eventi esposti dai
DataAdapter (RowUpdating, RowUpdated) ma, utilizzando il codice

precendete,
non posso agganciarmi in quanto IDbDataAdapter non espone gli eventi. Ho
verificato che anche la classe base DBDataAdpater non espone alcun evento.
"Corrado Cavalli [MVP]" <co*****************@mvps.org> wrote in message
news:#M**************@tk2msftngp13.phx.gbl...
Quale e' il problema usando la classe astratta DataAdapter come base

class
e
fargli implementare la IDbDataAdapter come fa il framework? (magari mi

sono
perso qualcosa...)

HTH

--
Corrado Cavalli [Microsoft .NET MVP-MCP]
UGIdotNET - http://www.ugidotnet.org
Weblog: http://www.ugidotnet.org/710.blog



Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Programatix | last post by:
Hi, I'm working on a WebService project. I'm trying to validate data before they are updated to the database by handling the RowUpdating event for a SqlDataAdapter. The data being handled has...
2
by: Vaap | last post by:
I am trying to get dataset working through IDbDataAdapter interface as my solution need to work with Sql Server and Oracle ODP. I am using different data provider factories and the code here only...
4
by: Maurizio | last post by:
Ciao a tutti, sto cercando di realizzare una classe (ProviderFactory) che mi consenta di scrivere del codice a prescindere dal provider utilizzato per accedere ai dati. Al momento gestisco i...
0
by: Steven Nagy | last post by:
Hidey ho, This question relates to IDbDataAdapter, DataSets, XML, and DiffGrams. I have a data adapter of type IDbDataAdapter and a dataset with one table in it, which has one row in it, which...
0
by: merco | last post by:
Hi. I have some problems using gridview bind to a datatable: i can't get updated values in then RowUpdating : i think the problem is that the datasource is nothing... I'm not using visual...
3
by: slemen | last post by:
The controls (textboxes) in the gridview row being updated have the old, pre user updated values in the RowUpdating event. Does anyone have an idea why? Thank you, Scott
9
by: John007 | last post by:
I am using a SQLDataSource to populate my gridview in ASP.Net 2.0. When I hit Edit, the textboxes appear and I am able to edit my values. When I hit Update, the changes are not saved, and there is no...
1
by: Steve Kershaw | last post by:
Hi, I'm using the RowUpdating() event of an updatable GridView. I need to see the values of the columns in the updated row. There has got to be a way to do this! Any suggestions? Thanks...
3
by: nick chan | last post by:
Hi i run into some difficulties getting rowupdating to fire when clicking Update link/button on gridview I set datasource at runtime, basically a datatable Edit and Cancel works. I don't know...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.