G
Guest
I created a very simple web page in asp.net.
there are only a textbox and a button on the page. when the page loads into
web browser there is current date in the textbox. but the date can be changed
by user as well.
now, when you press the button the date should be inserted into a database.
the problem is that , yes it has been inserted, but it is always the current
date. even if a user modified the date, it would be inserted the current date
into the db
why? how to changed that?
my code in aspx (c#):
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = DateTime.Now.ToShortDateString();
}
protected void Button1_Click(object sender, EventArgs e)
{
System.Data.SqlClient.SqlConnection con = new
System.Data.SqlClient.SqlConnection();
con.ConnectionString = "string";
con.Open();
System.Data.SqlClient.SqlCommand com = new
System.Data.SqlClient.SqlCommand("", con);
com.CommandText = "insert into table (date1) values ('" +
TextBox1.Text + "')";
com.ExecuteNonQuery();
con.Close();
}
there are only a textbox and a button on the page. when the page loads into
web browser there is current date in the textbox. but the date can be changed
by user as well.
now, when you press the button the date should be inserted into a database.
the problem is that , yes it has been inserted, but it is always the current
date. even if a user modified the date, it would be inserted the current date
into the db
why? how to changed that?
my code in aspx (c#):
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = DateTime.Now.ToShortDateString();
}
protected void Button1_Click(object sender, EventArgs e)
{
System.Data.SqlClient.SqlConnection con = new
System.Data.SqlClient.SqlConnection();
con.ConnectionString = "string";
con.Open();
System.Data.SqlClient.SqlCommand com = new
System.Data.SqlClient.SqlCommand("", con);
com.CommandText = "insert into table (date1) values ('" +
TextBox1.Text + "')";
com.ExecuteNonQuery();
con.Close();
}