Question working with different forms

mathumathi

Member
Joined
Mar 25, 2009
Messages
9
Programming Experience
Beginner
hai every one, i am involed in a project where i have four forms. access,oracle,sql and display resptly. the fourth form is common form for the other three forms. in the fourth form i have to write a code that opens connection to oracle database if its previous form is oracle or opens connection to sql database if its previous form is sql. can someone help me to do it
 
All the data-source-specific ADO.NET classes are derived from common classes. For instance, the OleDbConnection, OracleConnection and SqlConnection classes all inherit the DbConnection class. You can just have your common form accept a DbConnection object and then have your data-source-specific forms pass it the appropriate type of object.

You might also like to look at the DbProviderFactory, which can be used to create all the other ADO.NET classes. Again, the OleDbFactory, OracleClientFactory and SqlClientFactory all inherit the common class, so the common form can use the common type while the specific forms pass it the specific type. As an example, if your common form has a Factory property of type DbProviderFactory then you SQL Server form can assign a SqlClientFactory to that property, while your Oracle form can assign an OracleClientFactory. In the common form you can call CreateConnection to get a DbConnection object. That object will actually be either a SqlConnection or an oracleConnection, but both types inherit DbConnection so you can simply work with the common type.

Of course, your specific forms will also have to pass a connection string to your common form.
 
Back
Top