Typed Dataset and IDbDataAdapter

V

Vaap

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 shows SQL
Server.

My code snippets are

// Build the interface in provider factory (_pf in code below)
public IDbDataAdapter CreateDataAdapter()
{
return (IDbDataAdapter) new SqlDataAdapter();
}
....
Instantiate the class using reflection depending upon data provider
factory selection through web.config

//
....
public IDbDataAdapter DataAdapter = null;

public void prepareDataSet(string SQL)
{
connect();
DataAdapter = _pf.CreateDataAdapter();
DataAdapter.SelectCommand = _pf.CreateCommand(SQL,_connection);
}

I use this method from data access layer class to fill the dataset.

public DataSet GetContactAuth(DataSet ds)
{
string sql = "SELECT * FROM contact_auth";
db.prepareDataSet(sql);
db.DataAdapter.Fill(ds);
return ds;
}

I call this method from my business layer

public DatasetContactAuth execute(string userName, string password)
{
DatasetContactAuth dsLogin = null;
try
{
connectToDb();
ContactDAL dal = new ContactDAL(getDb());
dsLogin = (DatasetContactAuth) dal.GetContactAuth(new
DatasetContactAuth());
disconnectFromDb();
}
catch(Exception e)
{
ExceptionManager.Publish(e);
this.ErrorMsg = "Error in getting Contact information. Please
contact your system administrator.";
}
return dsLogin;
}

The Problem :

If I use typed dataset and use direct SQLClient API then I have to use
Fill(ds,"Table_name") to fill the dataset. Fill(ds) alone does not
work.

The IDbDataAdapter interface has only one overloaded method of Fill as
against 7 or more available in DBDataAdapter in System.Data.Common.

I am at loss to figure this out. Is there something, you can point out
to help me.

My requirements:

1. I have to use typed datasets. Weak datasets are not an option.
2. I have to use Interfaces to make code work with different data
providers.

How do I fill my typed dataset under this condition using
IDbDataAdapter interface.

I am new to .net so please pardon my ignorance.

I appreciate your help.

-Regards.
 
M

Miha Markic

Hi,
The Problem :

If I use typed dataset and use direct SQLClient API then I have to use
Fill(ds,"Table_name") to fill the dataset. Fill(ds) alone does not
work.

It works, but if probably fills another table (based on select from).
Either use that or pass DataTable directly to Fill.
The IDbDataAdapter interface has only one overloaded method of Fill as
against 7 or more available in DBDataAdapter in System.Data.Common.

I am at loss to figure this out. Is there something, you can point out
to help me.

My requirements:

1. I have to use typed datasets. Weak datasets are not an option.
2. I have to use Interfaces to make code work with different data
providers.

How do I fill my typed dataset under this condition using
IDbDataAdapter interface.

Every adapter is derived from DbDataAdapter.
So, you might just cast to DbDataAdapter or use DbDataAdapter instead of
IDbDataAdapter...
 
V

Vaap

Miha Markic said:
It works, but if probably fills another table (based on select from).
Either use that or pass DataTable directly to Fill.

You were right. The fill created a table name called "Table" and this
"table" got added in addition to one that was already there. - Thanks
Every adapter is derived from DbDataAdapter.
So, you might just cast to DbDataAdapter or use DbDataAdapter instead of
IDbDataAdapter...

I used this and then used overloaded method of fill(ds,"CONTACT_AUTH")
and it worked. - Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top