By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,935 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Typed Dataset and IDbDataAdapter

P: n/a
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.
Nov 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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...

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com
Nov 22 '05 #2

P: n/a
"Miha Markic" <miha at rthand com> wrote in message
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 ofIDbDataAdapter...


I used this and then used overloaded method of fill(ds,"CONTACT_AUTH")
and it worked. - Thanks
Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.