I have created a SQL table in Visual studio and set a default value on a field.

The table is connected to my C# project (in the same solution) and pulls through fine, however the default values are not appearing when a new row is created via a windows form.

Info from comment questions:
Based on this W3Schools Tutorials
The default value will be added to all new records IF no other value is specified.
So the Default value will not show until you save the row to the database, you can add it programatically, but the Default value constraint is used to assign a value if there is no values provided in this column
You can save these default values in the application Settings and use it when new row is added
textBox1.Text = Properties.Settings.Default.TextBoxDefaultValue;
If you are facing an issue when defining default value in Visual Studio try adding a Default Constraint using SQL query:
ALTER TABLE XXX
ADD CONSTRAINT def_Retired
DEFAULT 'N' FOR Retired;
UPDATE 1
On the form designer, click on the BindingNavigator, In the Properties window set the AddNewItem property to (none)
Try adding the following code to the bindingNavigatorAddNewItem_Click event
private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e) {
vehiclesBindingSource.AddNew();
Textbox1.Text = Properties.Settings.Default.Text1default;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With