Следующий код находится на странице сведений, которая получает запрос с другой страницы, а затем загружает данные на основе переданного идентификатора. Это работает отлично, но теперь моя проблема в том, что кнопка сохранения изменений не работает, как она должна быть; страница просто мигает, как она была отправлена, и загружает все значения обратно, я отлаживал, и все проходит отлично, что может быть проблемой? Может ли что-то делать со мной, используя строку запроса, потому что у меня есть другая команда обновления на другой странице (без строки запроса), и он прекрасно работает ...Таблица sql не обновляется при нажатии кнопки
namespace CC
{
public partial class customerdetails : System.Web.UI.Page
{
int customerID = 0;
protected void Page_Load(object sender, EventArgs e)
{
customerID = Convert.ToInt32(Request.QueryString["id"]);
string strConnString2 = "Data Source=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
using (SqlConnection con = new SqlConnection(strConnString2))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT CustomerStatus, CustomerGroup, CustomerFirstName, CustomerLastName, CompanyName, CustomerAddress, CustomerCity, CustomerState, CustomerZipcode, CustomerEmail, CustomerEmail2, CustomerPhoneNumber, CustomerPhoneNumberExt, CustomerType, CustomerSubscriptionType, CustomerCost, CustomerPaymentMethod, CustomerSignUpDate, CustomerPickUpDay, CustomerPickUpDay2, CustomerNotes FROM Customers WHERE CustomerID = @CustomerID";
cmd.Parameters.AddWithValue("@CustomerID", customerID);
con.Open();
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
if (reader["CustomerStatus"].ToString() == "New")
{
StatusLabel.ForeColor = System.Drawing.Color.YellowGreen;
}
else
{
if (reader["CustomerStatus"].ToString() == "Suspended")
{
StatusLabel.ForeColor = System.Drawing.Color.Aqua;
}
else
{
StatusLabel.ForeColor = System.Drawing.Color.DarkRed;
}
}
StatusLabel.Text = reader["CustomerStatus"].ToString();
if (reader["CustomerGroup"].ToString() == "")
{
}
else
{
GroupDropDown.SelectedValue = reader["CustomerGroup"].ToString();
}
txtCustomerFirstName.Text = reader["CustomerFirstName"].ToString();
txtCustomerLastName.Text = reader["CustomerLastName"].ToString();
txtCompanyName.Text = reader["CompanyName"].ToString();
txtCustomerAddress.Text = reader["CustomerAddress"].ToString();
txtCustomerCity.Text = reader["CustomerCity"].ToString();
txtCustomerState.Text = reader["CustomerState"].ToString();
txtCustomerZipcode.Text = reader["CustomerZipcode"].ToString();
txtCustomerEmail.Text = reader["CustomerEmail"].ToString();
if (reader["CustomerEmail2"].ToString() == "")
{
}
else
{
Email2CheckBox.Checked = true;
txtCustomerEmail2.Visible = true;
txtCustomerEmail2.Text = reader["CustomerEmail2"].ToString();
}
txtCustomerPhoneNumber.Text = reader["CustomerPhoneNumber"].ToString();
txtCustomerPhoneNumberExt.Text = reader["CustomerPhoneNumberExt"].ToString();
CustomerType.SelectedValue = reader["CustomerType"].ToString();
SubscriptionType.SelectedValue = reader["CustomerSubscriptionType"].ToString();
CostTxtBx.Text = reader["CustomerCost"].ToString();
CustomerPaymentMethod.SelectedValue = reader["CustomerPaymentMethod"].ToString();
CustomerSignUpDate.Text = reader["CustomerSignUpDate"].ToString();
PickUpDay.SelectedValue = reader["CustomerPickUpDay"].ToString();
if (reader["CustomerPickUpDay2"].ToString() == "")
{
}
else
{
PickUpDay2CheckBox.Checked = true;
PickUpDay2.Visible = true;
PickUpDay2.SelectedValue = reader["CustomerPickUpDay2"].ToString();
}
if (reader["CustomerNotes"].ToString() == "")
{
}
else
{
string sqlfriendlyNotes = reader["CustomerNotes"].ToString().Replace("<br/>", "\n");
NotesTxtBx.Text = sqlfriendlyNotes;
}
}
}
con.Close();
}
}
}
protected void SaveCustomerChanges_Click(object sender, EventArgs e)
{
string Status = this.StatusLabel.Text;
string Group = this.GroupDropDown.Text;
string customerStatus = Status;
string customerFirstName = this.txtCustomerFirstName.Text;
string customerLastName = this.txtCustomerLastName.Text;
string customerGroup = Group;
string companyName = this.txtCompanyName.Text;
string customerAddress = this.txtCustomerAddress.Text;
string customerCity = this.txtCustomerCity.Text;
string customerState = this.txtCustomerState.Text;
string customerZipcode = this.txtCustomerZipcode.Text;
string customerEmail = this.txtCustomerEmail.Text;
string customerEmail2 = this.txtCustomerEmail2.Text;
string customerPhoneNumber = this.txtCustomerPhoneNumber.Text;
string customerPhoneNumberExt = this.txtCustomerPhoneNumberExt.Text;
string customerType = this.CustomerType.Text;
string customerSubscriptionType = this.SubscriptionType.Text;
string customerCost = this.CostTxtBx.Text;
string customerPaymentMethod = this.CustomerPaymentMethod.Text;
string customerSignUpDate = this.CustomerSignUpDate.Text;
string customerPickUpDay = this.PickUpDay.Text;
string customerPickUpDay2 = this.PickUpDay2.Text;
string customerNotes = this.NotesTxtBx.Text.Replace("\n", "<br/>");
string strConnString1 = "Data Source=xxxxxxxxxxxxxx";
using (SqlConnection con = new SqlConnection(strConnString1))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "UPDATE Customers SET [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] WHERE CustomerID = @CustomerID";
cmd.Parameters.AddWithValue("@CustomerID", customerID);
cmd.Parameters.AddWithValue("@CustomerStatus", customerStatus);
cmd.Parameters.AddWithValue("@CustomerGroup", customerGroup);
cmd.Parameters.AddWithValue("@CustomerFirstName", customerFirstName);
cmd.Parameters.AddWithValue("@CustomerLastName", customerLastName);
cmd.Parameters.AddWithValue("@CompanyName", companyName);
cmd.Parameters.AddWithValue("@CustomerAddress", customerAddress);
cmd.Parameters.AddWithValue("@CustomerCity", customerCity);
cmd.Parameters.AddWithValue("@CustomerState", customerState);
cmd.Parameters.AddWithValue("@CustomerZipcode", customerZipcode);
cmd.Parameters.AddWithValue("@CustomerEmail", customerEmail);
cmd.Parameters.AddWithValue("@CustomerEmail2", customerEmail2);
cmd.Parameters.AddWithValue("@CustomerPhoneNumber", customerPhoneNumber);
cmd.Parameters.AddWithValue("@CustomerPhoneNumberExt", customerPhoneNumberExt);
cmd.Parameters.AddWithValue("@CustomerType", customerType);
cmd.Parameters.AddWithValue("@CustomerSubscriptionType", customerSubscriptionType);
cmd.Parameters.AddWithValue("@CustomerCost", customerCost);
cmd.Parameters.AddWithValue("@CustomerPaymentMethod", customerPaymentMethod);
cmd.Parameters.AddWithValue("@CustomerSignUpDate", customerSignUpDate);
cmd.Parameters.AddWithValue("@CustomerPickUpDay", customerPickUpDay);
cmd.Parameters.AddWithValue("@CustomerPickUpDay2", customerPickUpDay2);
cmd.Parameters.AddWithValue("@CustomerNotes", customerNotes);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
самое первое, что я бы сделать, это включить SQLProfiler и посмотреть, что на самом деле попадает в БД (если вы» re using SQL Server, то есть). – davek
Надеюсь, ваша кнопка отправки имеет обработчик, подобный этому onclick = "SaveCustomerChanges_Click" –
Вы уверены, что все параметры имеют тип данных текста? Вы добавляете их с помощью AddWitValue, и этот метод ищет тип данных значения для создания параметра. Однако некоторые имена полей выглядят разного рода (CustomerID, CustomerType, CustomerCost, SignUpDate)? – Steve