0

I'm new to C#. I trying to develop WPF application. In here when I press Save button I want to refresh the all the text box after insert values to database. How can I do that? Thanks..

addnewcategory.xaml.cs

    public addnewcategory()
    {
        InitializeComponent();
    }

    private void save_Click(object sender, RoutedEventArgs e)
    {
        string dbConn = "datasource=localhost;port=3306;username=root";
        string Query = "insert into tenderprocess.mstcategory (category) values('" + this.txtcategory.Text + "');";
        MySqlConnection mysqlConn = new MySqlConnection(dbConn);
        MySqlCommand cmdTenderprocess = new MySqlCommand(Query, mysqlConn);
        MySqlDataReader myReader;

        try
        {
            mysqlConn.Open();
            myReader = cmdTenderprocess.ExecuteReader();
            MessageBox.Show("New Category Successfully Saved");
            while (myReader.Read())
            {
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
}

}

Joe White
  • 94,807
  • 60
  • 220
  • 330
  • you can use of VisualTreeHelper and get all the child of type textbox and clear them – Ashok Rathod Aug 20 '14 at 04:13
  • @AshokRathod why do you need a VisualTreeHelper here ? – Sajeetharan Aug 20 '14 at 04:17
  • he wants to clear all the textboxes, probably mention it one by one, or using [visual tree helper](http://stackoverflow.com/questions/974598/find-all-controls-in-wpf-window-by-type) to find them – Yuliam Chandra Aug 20 '14 at 04:18
  • 1
    If you correctly use binding then you can just clear the appropriate properties, the UI will update itself. – slugster Aug 20 '14 at 04:24
  • @user2944679 . Use bindings, try MVVM,[HERE](http://stackoverflow.com/questions/1405739/mvvm-tutorial-from-start-to-finish) – Eldho Aug 20 '14 at 04:46

0 Answers0