Results 1 to 4 of 4

Thread: Set default values for new DataRows in Ado.Net

  1. #1
    Join Date
    Dec 2008
    Posts
    13

    Set default values for new DataRows in Ado.Net

    Hi,

    I have a dataGridView on a WindowsForm. The DataSource for the bindingSource is a DataSet containing a table, say Orders.
    When the addNewItem button on the navigator is pushed, I want to provide
    some default values for columns in the new row in the grid: e.g.
    CustomerNumber and OrderNumber (incremented by one).
    What is the usual way of doing this?

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Set default values for new DataRows in Ado.Net

    You should try the bellow given method for every column,

    dataGridView1.Columns[0].CellTemplate.DefaultNewRowValue

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Set default values for new DataRows in Ado.Net

    Check the given code,

    Code:
     '
        ' 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

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Set default values for new DataRows in Ado.Net

    This is same as above mentioned code but it is just given in the different format, you can use this also,

    Code:
     '
        ' 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)

Similar Threads

  1. W32 registry values are not getting matched by the default values
    By Angrzej in forum Networking & Security
    Replies: 5
    Last Post: 19-05-2011, 12:23 PM
  2. Vista - default printer doesn't stay as default
    By Freddie Kang in forum Vista Help
    Replies: 8
    Last Post: 19-04-2010, 03:12 AM
  3. What are the RGB values?
    By Renderman21 in forum Operating Systems
    Replies: 3
    Last Post: 21-11-2009, 09:45 AM
  4. How to use enum values in VB
    By $tatic in forum Software Development
    Replies: 1
    Last Post: 10-08-2009, 06:25 PM
  5. How to set default Java parameter values
    By StudyBoy in forum Software Development
    Replies: 3
    Last Post: 03-03-2009, 03:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,947,830.43787 seconds with 16 queries