Insert method of TableAdapter not working?

后端 未结 2 1886
既然无缘
既然无缘 2020-12-20 18:42

I\'m using ADO.NET in my C# project. In my form I added a SourceBinding element from my toolbox in VS2010. I set the connection to the table of my dataset. It creates a Data

相关标签:
2条回答
  • 2020-12-20 19:17

    I too was having difficulty figuring this out.

    You need to call DataSet.AcceptChanges() after the TableAdapter.Insert(...)

    That worked for me.

    So the steps are:

    1. Create your bindingsource, tableadapter and dataset using visual studio.
    2. TableAdapter.Fill(..) // this should automatically be added by vs.
    3. TableAdapter.Insert(..)
    4. DataSet.AcceptChanges()
    5. TableAdapter.Update(..)
    0 讨论(0)
  • 2020-12-20 19:40

    The table adapters are designed to be used with a dataset, to help you get data in and out of the DB using this dataset.

    Idea is that you can use the Dataset.NewYourTableNameRow() to create a new row for your dataset, then populate its fields and then call DataSet.AddYourTableNameRow(row) to put it in the dataset.

    Now you can orderTableAdapter.update(DataSet) to transmit that new row into the database.

    To delete or update a row, you would select it first into your dataset, perform a change to the object, then call the .update(ds) on the appropriate table adapter to send it back down.

    0 讨论(0)
提交回复
热议问题