typed datasets and default values

T

tg.foobar

my setup:

visual studio 2005
sql server 2000

i'm using a dataset (used to be called typed dataset in 2003), where i
use the MSDataSetGenerator to create a class for me based on the scheme
of my SQL server. This schema doesn't include the default values that
are defined in the SQL server. It's setting all the default values to
NULL. is thre an easy way to get around this? for example, i have a
"quantity" (byte) column in the "orders" table with a default value of
5, i would want to see:

mydataset._orders.columns("quantity").quantity.defaultvalue == 5

right now that value is DBNULL.

Yes, i know i can go into the schema and change the default value
there, but if i change hte database and need to regenerate the data set
then i need to change all the default values again. Yes, i know i can
make a wrapper class around the dataset (i actually have one already)
and put in a function that sets all the default values to the ones i
want at creation, but i have lots of tables and lots of columns and
that would be quite tedious. It seems like there should be an easier
way.
 
N

Nicholas Paldino [.NET/C# MVP]

You could always extend the MSDataSetGenerator. You would have to call
to the base generator, and then parse the code with CodeDom. Then, you
would have to connect to SQL Server to get the default values for the
columns in your data set, and adjust those.

You shouldn't need a wrapper class around the dataset. Rather, have a
method that takes the data set and takes a connection (or uses one it
already has).

Then, what you do is select the default values from the database for the
columns in the tables in the dataset. Once you have these, you can cache
the values for your table, and then prevent the excessive database hits.

Hope this helps.
 

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