dataAdapter for all DB?

AukI

Member
Joined
Nov 20, 2010
Messages
17
Programming Experience
3-5
Is there any way we could delecare a default dataAdapter to delete,update for all kinds Database(Oracle,Access,Sql) ...?


We have declare a oledb.oledbAdapter incase we need oledb databse object .. is there any way we can get default... or can we detect the adapter any how what we need.




like one adapter which delete ,update ,query in any databse.

Thanks in advance
 
If you want the lowest common denominator then use ODBC. There's an ODBC driver for pretty much every data source. You would then just need to change the connection string. You may need to change the SQL code a little too, because different data sources support different versions of SQL, all similar but not necessarily the same.

When working on Windows, OLE DB has very broad coverage too and it will certainly cover all the common data sources.
 
IDataAdapter is just an interface that all data adapters implement. SqlDataAdapter, OleDbDataAdapter, OdbcDataAdapter and all the others implement the IDataAdapter interface. If you wanted to create your own ADO.NET provider for a data source then you would define your data adapter class that also implemented IDataAdapter. You would have to provide all the low-level implementation though.

It's OK to use a provider other than SqlClient with SQL Server but you generally shouldn't unless you have a good reason to. Generally speaking, if you want to support multiple data sources then you would use a factory to generate objects of the appropriate type at run time. For more information on that, you may like to follow the Blog link in my signature and read my post on the subject.
 
like below

Public Function Connection_Create_BasedOnType(Optional ByVal ConnStr As String = Nothing) As [Object]
If ConnectionType = ConnectionTypeCategories.ODBC Then
If ConnStr Is Nothing Then ConnStr = ConnectionString
Dim Connection As New Odbc.OdbcConnection(ConnStr)
Return Connection
ElseIf ConnectionType = ConnectionTypeCategories.OLEDB Then
If ConnStr Is Nothing Then ConnStr = ConnectionString
Dim Connection As New OleDb.OleDbConnection(ConnStr)
Return Connection
ElseIf ConnectionType = ConnectionTypeCategories.SQL Then
If ConnStr Is Nothing Then ConnStr = ConnectionString
Dim Connection As New SqlClient.SqlConnection(ConnStr)
Return Connection
End If
End Function

Public Function DataAdapter_Create_BasedOnType(Optional ByVal ConnStr As String = Nothing, Optional ByVal SqlStr As String = "") As [Object]
If ConnectionType = ConnectionTypeCategories.ODBC Then
If ConnStr Is Nothing Then ConnStr = ConnectionString
Dim Adapter As New Odbc.OdbcDataAdapter(SqlStr, ConnStr)
Return Adapter
ElseIf ConnectionType = ConnectionTypeCategories.OLEDB Then
If ConnStr Is Nothing Then ConnStr = ConnectionString
Dim Adapter As New OleDb.OleDbDataAdapter(SqlStr, ConnStr)
Return Adapter
ElseIf ConnectionType = ConnectionTypeCategories.SQL Then
If ConnStr Is Nothing Then ConnStr = ConnectionString
Dim Adapter As New SqlClient.SqlDataAdapter(SqlStr, ConnStr)
Return Adapter
End If
End Function
 
If you've read my blog post then you know that that functionality is built into the Framework. Also in my blog it shows that you would use types DbConnection and DbDataAdapter rather than Object.
 
if I catch as a object , i do anything with it or else i have to create separate functions each time which is not smart...
 
if I catch as a object , i do anything with it or else i have to create separate functions each time which is not smart...

I don't really know what you just said but whatever it was it was wrong. Read my blog if you want to know more or don't. I'm not going to keep arguing the point when I've already spent hours writing about it specifically to help people like yourself.
 

Latest posts

Back
Top