• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 707
  • Last Modified:

Default value for DataRow Item

I have created a Table in SQL Server 2000 and has one column that
its default value is getdate() and dosen't allow null value.
I wrote a program by C# to connect to database and insert some rows in that
my question is when I want to insert a DataRow in DataSet and use
SqlDataAdapter Update method, how I can force the DataRow to use the
Default value for the column Instead of Null.
 (and dosen't generate exception for null value).

Thank you.
  • 2
1 Solution
Mohammed NasmanSoftware DeveloperCommented:
don't add this field to your select statement, and don't add it to DataRow
The InsertCommand property of the data adapter.

That SqlCommand object has the parameter collection from which, you should remove the parameter which you expect would receive the date values

In the SQL Statement or Stored Procedure
implicit use of getdate() since it is the default value

insert table1

or explicit

insert table1
MOH_RAuthor Commented:
mnasman :
It is not work. C# assume it as null value and my database generate an exception.
 b1xml2 :
I use disconnection database and working with DataSet and DataRow.
you write a connected code application.
Mohammed NasmanSoftware DeveloperCommented:

I meant, don't add the field in the select that used to fill the DataAdapter, so it will not be add to insert/update commands

show us your table and could, and we will help you to modify ti


Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now