tags:

views:

21

answers:

1

Hello everyone,

i am designing a local database in .net with wpf as gui. I have added a new database, and added a new table. Through the TableAdapter i generated 2 statements ( 1 statement is a select stmt and 1 is a insert) , i insert name and firstname (id is auto generated). It works fine, i can display the table in a datagrid (wpf toolkit) and also add new items (name,firstname), when i close and start the application everything is fine (data in table is stored) BUT when i try to preview data in my database dataset (where my Adapters exist) , no data is displayed and then the table gets deleted.. why?

public partial class MainWindow : Window
{



    public MainWindow()
    {
        this.InitializeComponent();

        PlayerTableAdapter objPlayerTableAdapter = new PlayerTableAdapter();
        objDataGridResults.ItemsSource = objPlayerTableAdapter.GetDataAllPlayer();
    }
    //Button Event onClick
    private void m_voidAddPlayer(object sender, System.Windows.RoutedEventArgs e)
    {
        PlayerTableAdapter objPlayerTableAdapter = new PlayerTableAdapter();
        objPlayerTableAdapter.InsertQueryPlayer(objTextBoxPlayerName.Text.ToString(), objTextBoxPlayerFirstName.Text.ToString());
        objDataGridResults.ItemsSource = objPlayerTableAdapter.GetDataAllPlayer();
    }
}
+1  A: 

the reason is that you modify not database, but dataset - the in-memory snapshot of database. When you close app it gets lost. You should call objPlayerTableAdapter.Update. And consider moving to Linq to SQL or Entity Framework, DataSets are outdated.

Andrey
I have tried to update with " this.objPlayerTableAdapter.Update(this.objProEvoDataset.Player); " but it still doesnt insert the values into my database...
testerwpf
@testerwpf read this: http://msdn.microsoft.com/en-us/library/ss7fbaez(VS.71).aspx it will tell you story from the very beginning
Andrey