Manually configuring a data adapter/ Wizard

R

Randy Fraser

Is there a way to manually configure the data adapters properties and use a
connection string that's already in my code? I read the connection string
from a configuration file and I don't want to use the
code generated by the dataAdapter configuration wizard.

Can I manually tell the data adapter to use select, insert, and update
commands that are in a database access class?

What I would like to do is use wizard to generate the code for my stored
procedures and parameters (because I'm lazy) but then I would like to move
this code to a db access class.

Best Regards

Randy
 
S

Scott Allen

Hi Randy:

Take a look inside the 'designer generated' code region and you should
find a method by the name of InitializeComponent.

Here you'll find all the code the designer spits out to configure the
adapter programatically. This is the same code you could use outside
of the webform/winform to configure the data adapter without the
designer, including setting your own connection string, and select,
insert, update commands.

HTH,
 
W

William Ryan eMVP

Hi Randy:
Randy Fraser said:
Is there a way to manually configure the data adapters properties and use a
connection string that's already in my code? I read the connection string
from a configuration file and I don't want to use the
code generated by the dataAdapter configuration wizard.

Yes, drag a connection object onto your form and then under its dynamic
properties http://www.knowdotnet.com/articles/attributes.html point it to
your config file. Then, just use that connection when configuring your
dataadapter.
Can I manually tell the data adapter to use select, insert, and update
commands that are in a database access class?

What I would like to do is use wizard to generate the code for my stored
procedures and parameters (because I'm lazy) but then I would like to move
this code to a db access class.

If I'm understanding your goal correctly, then No, you can't. you can
however get the config wizard to gen some code which you could modify and
add to your class. Then wipe all that out from the first form. You'll
already have the adapter and the connection, so declare an instance of your
class, set the update/delete/insert commands to your class (you'll probably
need to pass in your datatable or set it as a property).

If I misunderstood though, please let me know and I'll do my best to answer
it.
Best Regards

Randy

HTH,

Bill

www.devbuzz.com
www.knowdotnet.com
 
R

Randy Fraser

If you take a look at my reply to Bill you may be able to understand what I
am trying to accomplish.

I found the wizard very handy to generate a lot of code that I need to place
in my class. If I need to leave the code attached to the form and just
reconfigure the adapters connection string I will. But I much rather move
the code to entity classes.

If I have a global variable that contains a connection string, can I
manually enter this into the windows generated code or will this screw
things up?
 
R

Randy Fraser

Thanks for your reply Bill. I think you have an idea of what I want to do.

What are other people doing? If some one was going to build a Web

interface, mobile interface, and a Windows interface to their application, I

would assume that they would want to have most of the database access in

reusable classes.

The wizard is a great tool for generating some code. I crated a temporary

form and used the adapter configuration wizard to generate the stored

procedures and the parameters select, insert, update and delete. (Lets Say a

CustomerDB class). I would like to build these classes to return single

records or a Customer class and also a whole dataset. If I use a dataset I

would like it to use the class to automatically update the changes made to

the dataset passed from the form.

I am a bit confused on how this should be done. I would think it would be

quite common?

Can I mannually declare the Update command as a class function, the Insert

command as a class function and so on. If most of the dataAdapter

functionality is in the class instead of the form do I do this in the class

as well and just pass the dataset?

If you could give me a few words of wisdom I would appreciate it.

Best Regards

Randy
 

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