【发布时间】:2015-12-19 18:17:42
【问题描述】:
我目前正在制作一个电影院预订系统。将当前日期保存到数据库时,我使用以下代码保存当前日期:
scm.Parameters.AddWithValue("@booking_date", DateTime.Now);
这很好,直到我输入电影的时间,我从具有值 10:00、14:00 等的单选按钮中进行选择
单选按钮组名为 rbtime,我将其保存到数据库:
scm.Parameters.AddWithValue("@performance_time", rbtime.SelectedValue);
选中后显示当前时间,预订时间设置为 1900/01/01。但是,当我注释掉时:
scm.Parameters.AddWithValue("@booking_date", DateTime.Now);
它可以很好地保存从单选按钮中选择的时间。
我正在保存当前日期到日期和选定的时间到时间 (7) 数据类型。 你们有谁知道如何保存当前日期和不同的时间而不会像这样发生冲突?
Sql语句在这里:
string movie_ID = string.Empty;
string movie_Name = string.Empty;
string movie_certification = string.Empty;
string showing_ID = string.Empty;
string venue_name = string.Empty;
string UserId = string.Empty;
string UserName = string.Empty;
string seat_cat= this.rbseat_cat.SelectedItem.Text;
string performance_date = string.Empty;
string performance_time = string.Empty;
string booking_date = string.Empty;
string venue_ID = string.Empty;
int GVCount = GridView1.Rows.Count;
booking_date = DateTime.Now.ToString("dd/MM/yyyy");
foreach (GridViewRow GVRow in GridView1.Rows)
{
UserId = GVRow.Cells[0].Text;
UserName = GVRow.Cells[1].Text;
venue_ID = GVRow.Cells[2].Text;
venue_name = GVRow.Cells[3].Text;
showing_ID = GVRow.Cells[4].Text;
movie_ID = GVRow.Cells[5].Text;
movie_Name = GVRow.Cells[6].Text;
movie_certification = GVRow.Cells[7].Text;
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
SqlCommand scm = new SqlCommand();
scm.Connection = conn;
scm.CommandText = @"INSERT INTO booking
(user_ID, user_name, venue_ID,venue_name,showing_ID, movie_ID, movie_name, movie_cert, seat_cat, performance_date, booking_date, performance_time)
VALUES
(@UserID, @UserName, @venue_ID, @venue_name, @showing_ID, @movie_ID, @movie_Name, @movie_certification, @seat_cat, @performance_date,@performance_time, @booking_date)";
scm.Connection = conn;
scm.Parameters.AddWithValue("@movie_ID", movie_ID.ToString());
scm.Parameters.AddWithValue("@movie_Name", movie_Name.ToString());
scm.Parameters.AddWithValue("@movie_certification", movie_certification.ToString());
scm.Parameters.AddWithValue("@showing_ID", showing_ID.ToString());
scm.Parameters.AddWithValue("@venue_ID", venue_ID.ToString());
scm.Parameters.AddWithValue("@venue_name", venue_name.ToString());
scm.Parameters.AddWithValue("@UserId", UserId.ToString());
scm.Parameters.AddWithValue("@UserName", UserName.ToString());
scm.Parameters.AddWithValue("@booking_date", DateTime.Now);
scm.Parameters.AddWithValue("@performance_date", DateTime.Parse(DropDownListDate.SelectedItem.Text));
scm.Parameters.AddWithValue("@performance_time", rbtime.SelectedValue);
scm.Parameters.AddWithValue("@seat_cat", rbseat_cat.SelectedValue);
scm.ExecuteNonQuery();
conn.Close();
}
【问题讨论】:
-
为什么不将它们组合起来并存储在数据库中的单个列中,而不是将它们拆分为单独的列?
-
因为它们不相关。时间是看电影的时间不是订票的时间
-
它们不应该冲突。显示您的 SQL 语句。
标签: c# asp.net sql-server