【发布时间】:2014-01-22 10:31:49
【问题描述】:
在我的约会表中,我有 aDate、aTime、aContact、aHeight、aWeight、patientID、mcID 和 aStatus 字段。 aDate、aTime、aContact、aHeight、aWeight、patientID、mcID 值将通过文本框输入并插入到数据库中,但仅适用于 aStatus 字段,我希望它在创建时自动将名为(等待)aStatus 字段的值插入约会表中按钮被点击,aStatus怎么做?
protected void btnCreate_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sacpConnectionString"].ConnectionString))
{
try
{
SqlCommand cmd = new SqlCommand();
Guid guid;
guid = Guid.NewGuid();
string sql = "INSERT INTO appointment (aDate, aTime, aContact, aHeight, aWeight, patientID, mcID)";
sql += "VALUES (@aDate, @aTime, @aContact, @aHeight, @aWeight, @patientID, @mcID)";
cmd.Parameters.AddWithValue("@aDate", txtDate.Value);
cmd.Parameters.AddWithValue("@aTime", txtTime.Value);
cmd.Parameters.AddWithValue("@aContact", txtContact.Value.Trim());
cmd.Parameters.AddWithValue("@aHeight", txtHeight.Value.Trim());
cmd.Parameters.AddWithValue("@aWeight", txtWeight.Value.Trim());
cmd.Parameters.AddWithValue("@patientID", txtpatientID.Value.Trim());
cmd.Parameters.AddWithValue("@mcID", txtmcID.Value.Trim());
cmd.Connection = con;
cmd.CommandText = sql;
con.Open();
cmd.ExecuteNonQuery();
// Session.Add("Username", txtFirstName.Value);
// Session.Add("Password", txtContact.Value);
// FormsAuthentication.SetAuthCookie(txtFirstName.Value, true);
Response.Redirect("../index.aspx");
}
finally
{
con.Close();
}
}
}
}
【问题讨论】: