Hi,
Changes made in TextBox is not saved and, consequently, no changes occur in the data base These characteristics are set in the TextBoxes: OnTextChanged="NamеTextChanget" AutoPostBack="true". What do I need to change in the code? This is the code:
private string resultBase = "Произошло изменение";
string str;
string save_str;
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
using (SqlConnection conn = new SqlConnection(@"Data Source=IGELKOTT\YURKINSSON;Initial Catalog=BERGMAN_ADO;Integrated Security=True"))
{
int idd = Convert.ToInt32(Request.QueryString["id"]);
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Bergmans_Movies", conn);
DataTable dt = new DataTable();
conn.Open();
da.Fill(dt);
Idden.Text = dt.Rows[idd][0].ToString();
Filmnamn.Text = dt.Rows[idd][1].ToString();
conn.Close();
}
}
protected void NamnTextChanget(object sender, EventArgs e)
{
str = Filmnamn.Text;
newNamn.Text = resultBase + str;
}
protected void SubmitBtn_Click(Object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(@"Data Source=IGELKOTT\YURKINSSON;Initial Catalog=BERGMAN_ADO;Integrated Security=True"))
{
SqlCommand cmd = new SqlCommand("UPDATE Bergmans_Movies SET namn = @namn WHERE id = @id", conn);
conn.Open();
cmd.Parameters.AddWithValue("@id", Idden.Text);
cmd.Parameters.AddWithValue("@namn", str);
try
{
cmd.ExecuteNonQuery();
}
catch
{
Console.WriteLine("Data i tabellen дr inte lagts");
return;
}
int idd = Convert.ToInt32(Idden.Text);
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Bergmans_Movies", conn);
DataTable dt = new DataTable();
conn.Open();
da.Fill(dt);
Idden.Text = dt.Rows[idd][0].ToString();
Filmnamn.Text = dt.Rows[idd][1].ToString();
conn.Close();
}
}