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.
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.
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,d efault)
or explicit
insert table1
(col1,col2,col3,col_date)
values(@col1,@col2,@col3,g etdate())
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,d
or explicit
insert table1
(col1,col2,col3,col_date)
values(@col1,@col2,@col3,g
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.
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.