Setting Default Values before data is saved to SQL Database VB.NET Windows Form RRS feed

  • Question

  • I have a windows form that is very simple.  It has about 6 controls, bound to a SQL database.


    They are

    LastName (string) 

    FirstName (String)

    Quantity (Numeric)

    Price (Numeric)


    Orderdate (String) .. will contain string value of date and visible is set false


    All the data fields are bound to a data source


    The form is set up so that when a user changes either quantity or price, it recalculates the ExtPrice


    I want to update the OrderDate to the current date, prior to saving the data in the database.  This should be quite simple, but I cannot get it to work.  All the values, other than Orderdate are being set correctly.


    I have tried setting the value prior to the Me.Validate in the Save_Click event.  It does not set the value.

    I have tried setting it in the rowchanging event with the same results.


    The ExtPrice is being set using the validated events from Quantity and ExtPrice.  For testing purposes, however, I want the date updated whenever the record is saved, even if none of these three fields are changed


    This should be very simple.  I am trying this simple task because a more complex form that calculates and set a number of data values , based on user entry on the form, is not working.  So I thought I would try something simple.


    I am trying to perform the equivalent of an Access "Form Before Update" Event so I can set numerous values before the record is updated or saved.




    Monday, February 25, 2008 9:41 PM

All replies

  • Hi,


    I assume that you are using Datasets and DataTables.

    There are two events where you can take care of values xxxRowChanging (if you use a typed dataset) and TableNewRow.

    You have to add the event handler by code (in the constructor or the Form.Load event)

    AddHandler Me.DataSet1.Customers.CustomersRowChanging, yourHandler1

    AddHandler Me.DataSet1.Customers.TableNewRow, yourHandler2


    The CustomersRowChanging occurs after the row is changed in the UI but before the changes are applied to the DataTable.

    The TableNewRow allows you set defualt values for new rows.





    Monday, February 25, 2008 10:37 PM