DATE DATA TYPE CALCULATION IN ASP.NET
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial
class LIBRARY
: System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
}
protected void ButtonTOTALDAY_Click(object
sender, EventArgs e)
{
string
sCardNumber;
string
sBookNumber;
string
sStudentName;
string
sIssuedDate=TextBoxISSUE.Text;
DateTime
d1=Convert.ToDateTime(sIssuedDate);
string
sReturnDate=TextBoxRETURN.Text;
DateTime
d2=Convert.ToDateTime(sReturnDate);
int
iNumberOfDay;
sCardNumber = TextBoxCARD.Text;
sBookNumber = TextBoxBOOK.Text;
sStudentName = TextBoxNAME.Text;
iNumberOfDay = ((TimeSpan)(d2-d1)).Days;
TextBoxNOOFDAY.Text = Convert.ToString(iNumberOfDay);
}
protected void ButtonSAVE_Click(object
sender, EventArgs e)
{
string
connectionstring= ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;
string
insertsql = "insert into
library(cardnumber,bookname,name,issueddate,returndate,noofday)values(@cardnumber,@bookname,@name,@issueddate,@returndate,@noofday)";
using (SqlConnection myconnection = new SqlConnection(connectionstring))
{
myconnection.Open();
SqlCommand mycommand = new SqlCommand(insertsql,myconnection);
mycommand.Parameters.AddWithValue("@cardnumber",TextBoxCARD.Text);
mycommand.Parameters.AddWithValue("@bookname",TextBoxBOOK.Text);
mycommand.Parameters.AddWithValue("@name",TextBoxNAME.Text);
mycommand.Parameters.AddWithValue("@issueddate",TextBoxISSUE.Text);
mycommand.Parameters.AddWithValue("@returndate",TextBoxRETURN.Text);
mycommand.Parameters.AddWithValue("@noofday",TextBoxNOOFDAY.Text);
mycommand.ExecuteNonQuery();
myconnection.Close();
}
TextBoxCARD.Text = string.Empty;
TextBoxBOOK.Text = string.Empty;
TextBoxNAME.Text = string.Empty;
TextBoxISSUE.Text = string.Empty;
TextBoxRETURN.Text = string.Empty;
TextBoxNOOFDAY.Text = string.Empty;
}
}
#SradhaWebCreations
Contact : +91-9040573923, +91-7008182025
http://sradhawebcreations.com/
http://sradhawebcreations.blogspot.in/
https://facebook.com/sradhawebcreations
Contact : +91-9040573923, +91-7008182025
http://sradhawebcreations.com/
http://sradhawebcreations.blogspot.in/
https://facebook.com/sradhawebcreations
No comments:
Post a Comment