Search Amazon:

Set default values for new DataRows added to an ADO.NET DataTable

You use the DefaultValue property of the DataColumn object.

    '
    ' Set default values.
    '
    With myDataSet.Tables("Orders")
        .Columns("Order_Date").DefaultValue = Today
        .Columns("Quantity").DefaultValue = 1
        . . .
    End With

    '
    ' Add the new row.
    '
    Dim aNewRow As DataRow = myDataSet.Tables("Orders").NewRow
    myDataSet.Tables("Orders").Rows.Add(aNewRow)

You can also specify the values each time you add a row:

    '
    ' Create a new row, set its values and add it.
    '
    Dim aNewRow As DataRow = myDataSet.Tables("Orders").NewRow
    
    With myDataSet.Tables("Orders")
        .Columns("Order_Date") = Today
        .Columns("Quantity") = 1
        . . .
        .Rows.Add(aNewRow)
    End With
Sign In
  User Id 
  Password 


Submit Your Own Code and Articles




About TheScarms
About TheScarms

Ask me your programming questions

I read every email and answer all I can.

User Feedback: Be the first to add a comment! Items to Show:     

     
You must log in to post feedback.
Comment:    
 

If you use this code, please mention "www.TheScarms.com"

Email this page


TheScarms AppSentinel lets you securely copy protect and create evaluation versions of your software

TheScarms(tm) AppSentinel lets you quickly and easily create evaluation versions of your software and stop unauthorized copying and unregistered use of your programs!

Get your free
trial copy today!


      The World's Number 1 Web Host

© Copyright 2008 TheScarms