473,320 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

No Interface for CommandBuilder

codemama
I have written db provider independent code using interfaces (IDbDataAdapter)..
However in order to update a database from an XML file I need to use the Command Builder to generate the Insert and Delete Commands for me.

The issue comes in that the CommandBuilder does NOT have an interface..
So, this hoses up my provider independent code since now I have to create a CommandBuilder based on the provider type.. (OleDbCommandBuilder)


Any suggestions?

I guess I could extract the info from the XML file and generate the Insert and Delete Commands manually, but I was hoping to avoid this..

Thanks
Jan 9 '09 #1
1 2764
mldisibio
190 Expert 100+
Don't get discouraged. You are still on the right path.
First, let me say that if you can come up with a design that avoid the CommandBuilder, I would recommend it. Here is a quote from Microsoft themselves:

Initializing DataAdapters for Update

In ADO.NET, you must add your own code for submitting database updates to the DataAdapter object. There are three ways of doing this:
  • You can supply your own updating logic.
  • You can use the Data Adapter Configuration Wizard to generate the updating logic.
  • You can use the CommandBuilder object to generate the updating logic.
It is recommended that you supply your own updating logic. To save time, you can use the Data Adapter Configuration Wizard, but if you do, try not to generate the logic at run time. Do not rely on CommandBuilder objects unless you have to because your performance will suffer and you cannot control the updating logic the objects generate. In addition, a CommandBuilder will not help you submit updates using stored procedures.
You can use CommandBuilder with applications that dynamically generate data access logic, such as reporting or data extraction tools. Using the CommandBuilder eliminates the need for these tools to write their own code-generating modules.
That said, let's ignore that and move on. Creating a provider independent layer for data access is a Good Thing, so much so that MS provides a Data Access Application Block to do the same Designing for Database-Agnostic Applications

Their application block is very bloated and unwieldy. If you were to write you own, as you are doing, you need to have a good look at the classes in both System.Data AND System.Data.Common namespaces. Some of what you want to accomplish is provided by Interfaces, but other classes are provided via abstract classes.

In particular, look at the DbProviderFactory class. The concept is that each provider (SQLClient, Oracle, OLE DB, ODBC) will provide a provider-specific implementation of the classes (such as DBCommand, DBConnection, etc). Those classes follow the interface contract (IDbCommand for example) but you would actually work with the abstract classes, not the interfaces.

If you follow this so far, or spend some time understanding it, then you will see that even with a provider agostic data layer, you will eventually request a provider specific to Access, such as the OleDBFactory. Each concrete implementation of DbProviderFactory can create an instance of itself via a configuration string. That would be the only "provider specific" line of code. You can then work with the abstract class layer in a "provider agnostic" manner.

Okay. Still with me? The DbProviderFactory (abstract) has a "CreateCommandBuilder() method. So when you create your DbProviderFactory (which under the covers in your case will be a OleDbFactory implementation) you can call that method and get a DbCommandBuilder (which under the covers is an OleDBCommandBuilder instance for Access.
Jan 9 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Joao Santa Barbara | last post by:
Hi all i have a table with an autonumber field with a based select , i want to get all the three others commands, my problem is, i have a ds and i want to insert a new row ( my database gives...
10
by: Joao Santa Barbara | last post by:
hi all i need to work with the commandbuilder and with a transaction object how can i do this ???? thks JSB please don´t tell me that i have to do this ex:
1
by: Jason Shohet | last post by:
What we've done so far in our web applications: 1. We have no datasets dragged-and-dropped in Visual Studio. They are all defined in the code, generated at runtime. 2. when a user updates or...
3
by: Ed | last post by:
I just learned how to use the Commandbuilder and have researched it a little bit further and see that there is a dispose property. Should this be used after invoking the command builder or does...
9
by: whaletyr | last post by:
When I try to update an access database using the commandbuilder and updatecommand. I get the An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll ...
1
by: Jeremy | last post by:
When executing myda.update(myds,"cert"). I get the message "The field 'Cert.DateofInspection' cannot contain a Null value because the Required property for this field is set to True. Enter a...
1
by: cj | last post by:
I'm using the commandbuilder to generate insert commands for some tables for me. I provided it the select command "select * from mytable". I've used this on several tables and it was building the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.