dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Memberssabareesh reddy
Minu
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » .NET programming » ASP.NET/Web Applications

Insert or Update Null Values for DateTime Column of SQL Server through ASP.NET


Posted Date:     Category: ASP.NET/Web Applications    
Author: Member Level: Gold    Points: 10


Insert or Update Null Values for DateTime Column of SQL Server through ASP.NET. There are times there is a need to insert the null value in the datetime field in insert or update command text in asp.net that time we can use SqlDateTime.Null;



 


Learn how to Insert or Update Null Values for DateTime Column in SQL Server through ASP.NET


Insert or Update Null Values for DateTime Column of SQL Server through ASP.NET
there are times there is a need to insert the null value in the datetime field in insert or update command text in asp.net that time we can use SqlDateTime.Null;

Passing a nulll parameter to the Update/Insert command text in asp.net using c# code:

Datepage.aspx
DatePage
NameSpace used


using System.Data.SqlTypes;



protected void btnUpdate_Click(object sender, EventArgs e)
{
SqlConnection sCon =null;
SqlCommand sCmd =null;
try
{

sCon = new SqlConnection("server=localhost;database="";uid=sa;pwd=;");
sCmd = new SqlCommand("insert into TableName (Name,Date) Values(@Name,@Date) ", sCon );
sCmd.Parameters.Add("@Name", SqlDbType.Varchar,20).Value = txt1.Text;
if (txt1.Text != "")
sCmd.Parameters.Add("@Date", SqlDbType.SmallDateTime).Value = Convert.ToDateTime(txt2.Text);
else
sCmd.Parameters.Add("@Date", SqlDbType.SmallDateTime).Value = SqlDateTime.Null;

sCmd.CommandTimeout = 30;
sCmd.ExecuteNonQuery();
catch (Exception ex)
{
MsgMsg(ex.Message);
}
finally
{
if (sCon.State == ConnectionState.Open)
{
sCon.Close();
sCon.Dispose();
}
}
}





Did you like this resource? Share it with your friends and show your love!


Responses to "Insert or Update Null Values for DateTime Column of SQL Server through ASP.NET"
Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Session State ASP.NET 4.0
    Previous Resource: Adding the specified count to the semaphore would cause it to exceed its maximum count. c#
    Return to Resources
    Post New Resource
    Category: ASP.NET/Web Applications


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    SqlDBNull  .  



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.