Custom DataAdapter Class

J

Jeverson

Hi All,

I'm tryin' to create a new DataAdapter class. This class
inherits from System.Data.Common.DbDataAdapter and
implements the following interfaces: IDbDataAdapter and
ICloneable.

Here is the class declaration and a simplified version of
the constructor called by VS.NET:
[Serializable()]
public class PIDataAdapter :
System.Data.Common.DbDataAdapter, IDbDataAdapter,
ICloneable
{
public PIDataAdapter()
{
try
{
this.mobjSqlDataAdapter = new
System.Data.SqlClient.SqlDataAdapter();
this.miAdapter = (IDbDataAdapter) this.mobjSqlDataAdapter;
this.SelectCommand = (IDbCommand) new
System.Data.SqlClient.SqlCommand();
}
catch
{
}
}
.... }


The code compiles ok and I can even add an instance of
this class to a web form designer, but there are some
things that are not Ok. Here are they:

1. The SelectCommand property of the class doesn't get
initialized in the code-behind file of the page I add it
to. Is the constructor the right place for doing this? or
do I have to catch any event for doing the initialization?
How to write the values of the initialization in the code-
behind file of the page where I add the component?

2. When I right click the PIDataAdapter instance, the
following options are NOT present in the context menu:
Configure DataAdapter..., Generate Dateset..., Preview
Data...

What am I doing wrong? Could anyone please help me?
I've spent a lot of time trying to figure out what is
wrong but didn't get anywhere ...

Thanks in advance,
Best Regards,

Jeverson
 
R

Ross Donald

Hi Jeverson,

The DataAdapters that are a part of the .NET Framework have custom
UITypeEditors attached to them so that you can use the wizards to create
stored procedures and commands etc.

The way this is done is by the use of Attributes from the
System.ComponentModel namespace that allow a designer to be specified for a
class or property. For example the SqlDataAdapter has a
SqlDataAdapterDesigner associated with it. This is done by the use of the
DesignerAttribute on the SqlDataAdapter class. Individual properties for a
class can also have designers (see EditorAttribute class). The editor is
displayed when the "..." button is pressed next to the property.

You would have to make your own designer and editors as the Microsoft
designer classes are internal to the framework.

// C# - rough guide only
using System;
using System.ComponentModel;

[Designer("Microsoft.VSDesigner.Data.VS.SqlDataAdapterDesigner")]
public sealed class SqlDataAdapter : DbDataAdapter, IDbDataAdapter
{
//...
[Editor("Microsoft.VSDesigner.Data.VS.DBCommandEditor")]
public SqlCommand UpdateCommand { ... }
//...
}

There is a newsgroup that covers this topic, see:
microsoft.public.dotnet.framework.windowforms.designtime

If you want to know more about how the .NET Framework classes work I would
suggest getting .NET Reflector (http://www.aisto.com/roeder/dotnet) and
reading up on the System.ComponentModel namespace.

--
Ross Donald
http://www.radsoftware.com.au/web/WebLog


Jeverson said:
Hi All,

I'm tryin' to create a new DataAdapter class. This class
inherits from System.Data.Common.DbDataAdapter and
implements the following interfaces: IDbDataAdapter and
ICloneable.

Here is the class declaration and a simplified version of
the constructor called by VS.NET:
[Serializable()]
public class PIDataAdapter :
System.Data.Common.DbDataAdapter, IDbDataAdapter,
ICloneable
{
public PIDataAdapter()
{
try
{
this.mobjSqlDataAdapter = new
System.Data.SqlClient.SqlDataAdapter();
this.miAdapter = (IDbDataAdapter) this.mobjSqlDataAdapter;
this.SelectCommand = (IDbCommand) new
System.Data.SqlClient.SqlCommand();
}
catch
{
}
}
... }


The code compiles ok and I can even add an instance of
this class to a web form designer, but there are some
things that are not Ok. Here are they:

1. The SelectCommand property of the class doesn't get
initialized in the code-behind file of the page I add it
to. Is the constructor the right place for doing this? or
do I have to catch any event for doing the initialization?
How to write the values of the initialization in the code-
behind file of the page where I add the component?

2. When I right click the PIDataAdapter instance, the
following options are NOT present in the context menu:
Configure DataAdapter..., Generate Dateset..., Preview
Data...

What am I doing wrong? Could anyone please help me?
I've spent a lot of time trying to figure out what is
wrong but didn't get anywhere ...

Thanks in advance,
Best Regards,

Jeverson
 

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