1
`protected void Page_Load(object sender, EventArgs e)
{
TextBox6.Text = DateTime.Now.ToShortDateString();
TextBox7.Text = DateTime.Now.AddMonths(6).ToShortDateString();
}` protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=ASHISH;Initial Catalog=esaote;Integrated Security=True");
string q = "insert into info(c_name,c_address, machine, s_version, email,i_ date,due_date) values(@c_name, @c_address, @machine, @s_version, @email, @i_date,@due_date)";
SqlCommand cmd = new SqlCommand(q, con);
cmd.Parameters.AddWithValue("@c_name", TextBox1.Text);
cmd.Parameters.AddWithValue("@c_address", TextBox2.Text);
cmd.Parameters.AddWithValue("@machine", TextBox3.Text);
cmd.Parameters.AddWithValue("@s_version", TextBox4.Text);
cmd.Parameters.AddWithValue("@email", TextBox5.Text);
cmd.Parameters.AddWithValue("@i_date",TextBox6.Text);
cmd.Parameters.AddWithValue("@due_date", TextBox7.Text);
//string due_date = DateTime.Now.ToShortDateString() + DateTime.Now.AddMonths(6).ToShortDateString();
try
{
con.Open();
cmd.ExecuteNonQuery();
Response.Redirect("<script language='javascript'>alert('due date is'" + TextBox7.Text + ")</script>");
}
catch (Exception exp)
{
Console.Write(exp.Message);
}
finally
{
con.Close();
}
}
catch塊給出了不正確的語法近日期異常。我已將最後一次cmd.parameter中的i_date更改爲due_date。表中的所有屬性都與給定的名稱相同,我無法找到sol。也有轉換的語法無法插入數據ino表
謝謝你的工作完美 – user1517636