0
獲取文本框的值,我想更新此窗體的登錄和註銷時間:無法在Update方法
我的代碼是:
protected void btnUpdate_Click(object sender, EventArgs e)
{
string LoginTime = txtIn.Text;
string LogOutTime = txtOut.Text;
long DayLogId = Convert.ToInt64(Request.QueryString["ID"]);
System.Data.SqlClient.SqlConnection dataConnection = new SqlConnection();
dataConnection.ConnectionString [email protected]"Data Source=DELL\SQLSERVER1;Initial Catalog=LoginSystem;Integrated Security=True";
System.Data.SqlClient.SqlCommand dataCommand = new SqlCommand();
dataCommand.Connection = dataConnection;
//tell the compiler and database that we're using parameters (thus the @first, @last, @nick)
dataCommand.CommandText = ("UPDATE [DayLog] SET [LoginTime][email protected],[LogOutTime][email protected] WHERE [DayLogId][email protected]");
//add our parameters to our command object
dataCommand.Parameters.AddWithValue("@LoginTime", LoginTime);
dataCommand.Parameters.AddWithValue("@LogOutTime", LogOutTime);
dataCommand.Parameters.AddWithValue("@DayLogId", DayLogId);
dataConnection.Open();
dataCommand.ExecuteNonQuery();
dataConnection.Close();
}
在方法的前兩行,
string LoginTime = txtIn.Text;
string LogOutTime = txtOut.Text;
當我調試時,它不顯示我重新輸入的值特德。此代碼的工作,如果我寫碼的手動
string LoginTime = "11:44:11";
string LogOutTime = "12:44:11";
注:
在文本框中形式的值從另一頁GridView的到來。
protected void grdEmployee_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "View")
{
GridViewRow grRow = ((Control)e.CommandSource).NamingContainer as GridViewRow;
Label DayLogId = grRow.FindControl("lblDayLogId") as Label;
if (Convert.ToInt16(DayLogId.Text) > 0)
{
Response.Redirect("~/Employee/OutLog_Day.aspx?ID=" + DayLogId.Text, false);
}
}
}
gridview和表單之間的關係是什麼?一個人的更新應該觸發另一個人的更新嗎? – Christos
這是一種症狀,通常與Page_Load事件 – Steve
上缺少的IsPostBack測試相關聯,後者發佈您的頁面加載事件 –