Link to home
Start Free TrialLog in
Avatar of MOH_R
MOH_R

asked on

Default value for DataRow Item

Hello.
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
table.
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.
Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of image

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
(col1,col2,col3,col_date)
values(@col1,@col2,@col3,default)


or explicit

insert table1
(col1,col2,col3,col_date)
values(@col1,@col2,@col3,getdate())
Avatar of MOH_R
MOH_R

ASKER

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.
------------------------------------------------------------------------------------------------
ASKER CERTIFIED SOLUTION
Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial