Default value for DataRow Item

Posted on 2005-05-14
Last Modified: 2010-05-18
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.
Question by:MOH_R
    LVL 22

    Expert Comment

    don't add this field to your select statement, and don't add it to DataRow
    LVL 23

    Expert Comment

    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
    LVL 1

    Author Comment

    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.
    LVL 22

    Accepted Solution


    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

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now