I may be confused. You are adding new records locally to a datatable and
you want the a given default value to appear when you first add a new row.
For each column that has a default value in the DB, (if your query is Select
first, second, third, forth from MyTable) and first, and forth have a
default of "Default", then do this...
myDatatable.Columns[0].DefaultValue = "Default";
myDatatable.Columns[3].DefaultValue = "Default";
Now when you add a new value you are good to go. Unless I'm
misunderstanding, this should solve the problem. Default values don't
usually change in a db and they're not going to change during a user session
so setting them at the onset shouldn't be a big deal. Moreover, if you were
to leave the defaults out, and submit your update, they'd be added by the DB
when the insert happened and if you had the refresh dataset option on or
insert logic that refreshed for you, the new values would apper in your app.
Functionally, there'd be little difference. However, if you want the fields
in the app to have the default value before they go to the db (so the user
will see exactly what's going to be in the db) , then set the DefaultValue
property in the column to match its counterpart in the db
I admit though that I may be misunderstanding so if I am,please let me know
and I'll do my best.
Cheers,
BIll
Hi William,
Indeed it is possible to set them manually but isn't it possible for .NET
to set the defaultvalue of the control on the form automatically with the
defaultvalue from the database.
This because when I change the defaultvalue in de database I don't have
to edit my code.
The Datacolumn object has a defaultvalue property.. Say that Column1
in your Db named FirstCol has a defaultvalue of "1" in Access..
assuming FirstCol was the first field in your SQL Query..
myDataSet.Tables["MyTable"].Column[0].DefaultValue = "1"
You can do that for each one locally so it matches your defaults in
the db. "Maurice Mertens said:
Hi,
I have an Access database in which I defined default values for
certain columns. On my windows forms I've got controls bound to the
dataset, The problem is that when I add a new row to the dataset my
controls don't have the defaultvalue entered in the database.
Is it possible to retrieve the defaultvalue for the column from the
database?
--
Met vriendelijke groet / With regards / Saludos,
Moviat Automatisering
Maurice Mertens
mauricem@moviat_KillSpamWordForEMail.nl
tel: +31 162 470 534
fax: +31 162 470 502
--
Met vriendelijke groet / With regards / Saludos,
Moviat Automatisering
Maurice Mertens
mauricem@moviat_KillSpamWordForEMail.nl
tel: +31 162 470 534
fax: +31 162 470 502