win表单保存的数据,输入日期格式为(dd/mm/yyyy)。数据库以 (yyyy-mm-dd) 格式显示。如何更改日期格式?
private void btnAllocate_Click(object sender, EventArgs e)
{
for (int i = 0; i < dgvDetails.Rows.Count; i++)
{
SqlConnection con = new SqlConnection("server=HP-HP; database=Restaurent; user id=sa; password=sql2008");
SqlCommand cmd = new SqlCommand("INSERT INTO WtrTblAllot (WtrNm,Type,No,currDate) values (@WtrNm,@Type,@No,@currDate)", con);
cmd.Parameters.AddWithValue("@WtrNm", dgvDetails.Rows[i].Cells[0].Value);
cmd.Parameters.AddWithValue("@Type", dgvDetails.Rows[i].Cells[1].Value);
cmd.Parameters.AddWithValue("@No", dgvDetails.Rows[i].Cells[2].Value);
cmd.Parameters.AddWithValue("@currDate", dtTmPkr.Value);
con.Open();
cmd.ExecuteNonQuery();
cmd = null;
}
MessageBox.Show("Added successfully!");
}
日期时间标记 (dtTmPkr) 格式 (dd/mm/yyyy)