0
데이터베이스에서 검색 한 값으로 채워진 양식이 있습니다. 해당 양식에는 제출 버튼이있어서 클릭하면 데이터베이스의 해당 필드를 업데이트해야합니다.업데이트 양식은 원래 값을 유지합니다.
문제는 무엇을해도 값이 데이터베이스에서 업데이트되지 않는다는 것입니다. 저장 프로 시저를 사용하고 두 번 체크했는데, 잘 작동합니다. 또한 하드 코드 된 삽입 값으로 트릭을 시도했습니다.
내 생각에 Page_Load에서 데이터베이스의 필드가 채워지면 값을 변경하더라도 해당 값이 유지됩니다. 같은 양식을 사용하여 데이터를 검색하고 업데이트 할 수 있도록이 문제를 어떻게 극복합니까?
protected void Page_Load(object sender, EventArgs e)
{
lblMsg.Visible = false;
string bookingid = Request.QueryString["bookingid"];
Booking b = BookingAccess.GetBooking(Int32.Parse(bookingid));
if (b != null)
{
var start_date_formatted = ((DateTime)b.StartDate).ToString("dd-MM-yyyy");
var end_date_formatted = ((DateTime)b.EndDate).ToString("dd-MM-yyyy");
pet_name.Text = b.PetName;
species.Text = b.Species;
start_date.Text = start_date_formatted;
end_date.Text = end_date_formatted;
}
}
protected void btnEditBooking_Click(object sender, EventArgs e)
{
string bookingid_raw = Request.QueryString["bookingid"];
int bookingid = int.Parse(bookingid_raw);
var start_date_formatted = DateTime.ParseExact(start_date.Text, "dd-MM-yyyy", null);
var end_date_formatted = DateTime.ParseExact(end_date.Text, "dd-MM-yyyy", null);
string pet_name = "a";
string species = "b";
lblMsg.Visible = true;
string msg = BookingAccess.UpdateBooking(bookingid, pet_name, species, start_date_formatted, end_date_formatted);
if (msg == null)
lblMsg.Text = "Updated booking details successfully!";
else
lblMsg.Text = "Error -> " + msg;
}
코드를 추가하십시오. 다시 게시 할 때 필드를 채우지 않도록하십시오. – MikeSmithDev