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();
            
        }
    }

Hi,
I fixed it by my self. This is code:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!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();
                Manuskript.Text = dt.Rows[idd][2].ToString();
                Roll.Text = dt.Rows[idd][3].ToString();
                Musik.Text = dt.Rows[idd][4].ToString();

                conn.Close();

            }
        }
    }

    protected void NamnTextChanget(object sender, EventArgs e)
    {
        newFilmnamn.Text = Filmnamn.Text;
        newDeskript.Text = Manuskript.Text;
        newRoll.Text = Roll.Text;
        newMusik.Text = Musik.Text;
    }

    protected void SubmitBtn_Click(Object sender, EventArgs e)
    {

        using (SqlConnection conn = new SqlConnection(@"Data Source=IGELKOTT\YURKINSSON;Initial Catalog=BERGMAN_ADO;Integrated Security=True"))
        {
            conn.Open();

                SqlCommand cmd = new SqlCommand("UPDATE Bergmans_Movies SET namn = @namn, deskription = @deskription, roll = @roll, musik = @musik WHERE id = @id", conn);
                
                
                cmd.Parameters.AddWithValue("@id", Idden.Text);
                cmd.Parameters.AddWithValue("@namn", newFilmnamn.Text);
                cmd.Parameters.AddWithValue("@deskription", newDeskript.Text);
                cmd.Parameters.AddWithValue("@roll", newRoll.Text);
                cmd.Parameters.AddWithValue("@musik", newMusik.Text);
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch
                {
                    Console.WriteLine("Data i tabellen är inte lagts");
                    return;
                }


                conn.Close();
            
        }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.