开发者

.net Studio Local Database

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜