Class question

  • Thread starter Thread starter Greg
  • Start date Start date
G

Greg

Say I have a database with a table called "Customers" and I want to create a
class that has the properties CustomerID and CustomerName, which I want to
be able to read as well as update. So if I say, Customers.CustomerName =
"Bob", it will update the row in the table automatically? Is there a way to
do this, or would need to call an update sub afterwords that would do the
updates?
 
Greg,

You can do that, however it is easier to inherit the dataset for that, than
completly do that job again yourself what they did at Microsoft.

When you open an item xsd file, type in the elements Customers and in that
the Element CustomerID and and Element CustomerName. Than tell with a right
click to generate a dataset, than will that class be made for you.

You can find it than in the solution explorer when you tell show all files
beneath the XSD that you have used.

I hope this helps?

Cor
 
Hi Greg,

If you are building a fairly complex application you may want to learn more
about a common solution for what you describe - a data tier. Read this
article, it may help you decide:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/buildntierapp.asp

Data tiers are not always necessary, as the article explains too.

If you don't need a data tier you can get what you want by using some of the
built-in capabilities of the ADO.NET namespace classes. In particular using
a strongly typed dataset will let you auto generate a Customer class that
ties well to ADO.NET capabilities.

Generating a strongly typed DataSet from your database table(s) will
generate a class for each table you choose to include in the DataSet. For
example if you include your Customers database table when you generate the
strongly typed DataSet, a Customer class will be generated in the DataSet.
Using ADO.NET you can bind the Customer object to various controls. You can
load data, modify a Customer, add a new Customer, delete a Customer, and
update the database using the DataSet's Customer class and ADO.NET.

Here is a link to a list of articles about creating and using DataSets which
includes information about strongly typed datasets:

http://msdn.microsoft.com/library/d...s/cpguide/html/cpconcreatingusingdatasets.asp


--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
 

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

Back
Top