i have to fields as follows
fromdate calendarimage
Todate calendarimage
which date i choose that date displayed both in the fromdate and todate.but in the database date stored in the format as 1/1/1900 12:00:00 AM.
why?
fromdate and todate datatype is datetime in the database.
when i insert the date for this query as follows
SqlCommand cmd = new SqlCommand("insert into BirthDayWish values('" + txt_name.Text + "','" + FromDate.SelectedDateValue.ToString() + "','" + txt_mobile.Text + "','" + Todate.SelectedDateValue.ToString() + "','a','" + txt_Email.Text + "')", con);
please help me.
Satyapriya NayakPosted Dec 24, 2012, 4:30 AM
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace WebApplication11
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString;
string str;
SqlCommand cmd;
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "INSERT INTO BirthDayWish VALUES (@dof)";
cmd = new SqlCommand(str, con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@dof", FromDate.SelectedDate.ToString("dd/MM/yyyy"));
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
Response.Write("Records Inserted");
}
}
}
Vishnujeet KumarPosted Dec 24, 2012, 4:09 AM
go through this link .
http://www.sql-server-helper.com/tips/date-formats.aspx