Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-01-2009
Member
 
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?
Reply With Quote
  #2  
Old 26-01-2009
Member
 
Join Date: May 2008
Posts: 2,293
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
Reply With Quote
  #3  
Old 26-01-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
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
Reply With Quote
  #4  
Old 26-01-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
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)
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 11:12 PM.